-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists.py
49 lines (32 loc) · 1.11 KB
/
lists.py
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
39
40
41
42
43
44
45
46
47
48
49
"""
A python program about lists.
"""
friends = ['Abhinav', 'Ekansh', 'Yatharth', 'Nitin', 'Vikas', 'Yatharth']
print(friends[-2])
print(friends[1:])
print(friends[1:3])
friends[1] = 'Ketki' # to change the value of the elements in the list.
# functions
lucky_numbers = [3, 7, 11, 17, 99, 69]
# friends.extend(lucky_numbers) # extend function
print(friends)
friends.append('Saumya') # append function
print(friends)
friends.insert(2, 'Kavana') # insert function
print(friends)
friends.remove('Nitin') # remove function
print(friends)
friends.pop() # pop's one element out of the list
print(friends)
print(friends.index('Kavana')) # to check the index of an element
print(friends.count('Yatharth')) # to count the occurence of a certain element.
friends.sort() # to sort the list on alphabatical or increasing order.
print(friends)
lucky_numbers.sort()
print(lucky_numbers)
lucky_numbers.reverse() # to reverse the list
print(lucky_numbers)
friends_2 = friends.copy() # to copy a list
print(friends_2)
friends.clear() # clear function (erases everything)
print(friends)