-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.py
64 lines (63 loc) · 1.23 KB
/
list.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#LIST AND TUPLE
a=[1,3,5,7,2,4,6,8]
#PRINT THE LIST USING PRINT() FUNCTION
print(a)
#Access using index using a[0],a[1],a[2]
print(a[5])
#Changes the value of the list using
a[3]=9
print(a)
#We can Create a list with items of the difffrent types
c=[45, "Marry",False,6.9]
print(c)
#Sort
l1=[2,12,4,6,16,23,43]
l1.sort()
print(l1)
#Reverse
l1=[2,12,4,6,16,23,43]
l1.reverse()
print(l1)
#Appends adds at the end of the list
l1=[2,12,4,6,16,23,43]
l1.append(47)
print(l1)
#Insert
l1=[2,12,4,6,16,23,43]
l1.insert(2,5)
print(l1)
#pop remove element at index
l1=[2,12,4,6,16,23,43]
l1.pop(5)
print(l1)
#Remove [remove of the list]
l1=[2,12,4,6,16,23,43]
l1.remove(12)
print(l1)
#CREATING LIST IN A DIFFRENT METHODS
fruits=['Apples','orange','grapes','pears']
#Get Value a single value with indexing
print(fruits[1])
#Get length
print(len(fruits))
#Get Append to List
fruits.append('Mangoes')
print(fruits)
#Remove from list
fruits.remove('grapes')
print(fruits)
#Insert into position
fruits.insert(2,'kiwi')
print(fruits)
#POP remove element form list
fruits.pop(4)
print(fruits)
#Sort list it set by an alphabetic order
fruits.sort()
print(fruits)
#Reverse Sort
fruits.sort(reverse=True)
print(fruits)
#Change Value
fruits[0]="Blueberries"
print(fruits)