-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_functions.py
More file actions
49 lines (34 loc) · 2.16 KB
/
list_functions.py
File metadata and controls
49 lines (34 loc) · 2.16 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
39
40
41
42
43
44
45
46
47
48
49
# Builtin methods for list
L1 = ["John", 102, "USA","iqra",7.89,33,"irtaza",4,7,4]
print(L1)
print(L1.clear()) # clear() Removes all the elements from the list
print("///////////////////////////////////////////////////////////")
print(L1.copy()) # copy() Returns a copy of the list
print("///////////////////////////////////////////////////////////")
print(L1.count(4)) # count() Returns the number of elements with the specified value
print("///////////////////////////////////////////////////////////")
number = [3,5] # extend() Add the elements of a list (or any iterable), to the end of the current list
number.extend(L1)
print("updated list is : " ,number)
print("///////////////////////////////////////////////////////////")
print(L1.index('iqra')) # index() Returns the index of the first element with the specified value
print("///////////////////////////////////////////////////////////")
L1.insert(4,"talha") # insert() Adds an element at the specified position
print(L1)
print("///////////////////////////////////////////////////////////")
L1.pop() # pop() Removes the element at the specified position
print(L1)
print("///////////////////////////////////////////////////////////")
L1.append(7) # append() Adds an element at the end of the list
print(L1)
print("///////////////////////////////////////////////////////////")
L1.remove('USA') # remove() Removes the first item with the specified value
print(L1)
print("///////////////////////////////////////////////////////////")
L1.reverse() # reverse() Reverses the order of the list
print(L1)
print("///////////////////////////////////////////////////////////")
L2 = [5,9,0,3,1,5]
print(L2)
L2.sort() # sort() Sorts the list
print(L2)