-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.py
More file actions
38 lines (32 loc) · 1.03 KB
/
lists.py
File metadata and controls
38 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#practice with lists
friends = ["Anthony" , "Juan", "Marcelo", "Justin", "Miguel", "Staphany"]
#lists can hold a variety of variables and will run fine
print(friends)
print(friends.index("Staphany"))
print(friends[0]) #accesses the position in the list
print(friends[-2])#backdoor indexing/begins at -1
friends[1] = "Juana"#modification of list
print(friends[1])
#using functions for lists
lucky_numbers = [2, 5, 15, 23, 25, 41, 100]
#extend function - appends lists together
friends.extend(lucky_numbers)
print(friends)
#add individual elements instead of entire list
friends.append("Edgar") #adds to end of list
friends.insert(2, "Andrea") #locates index position and adds new name to list
print(friends)
friends.remove("Marcelo")
print(friends)
friends.pop()#gets ride of last element in this list
print(friends)
friends.clear()#clears entire list
print(friends)
#sort
lucky_numbers.sort()
print(lucky_numbers)
lucky_numbers.reverse()
print(lucky_numbers)
#copy
friends2 = friends.copy()
print(friends2)