-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script4.py
74 lines (49 loc) · 1.17 KB
/
Script4.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
65
66
67
68
69
70
71
72
73
74
print(len([1,2,3,4]))
list = [1,2,3,4,5]+[6,7,8,9,10]
print(list)
list1 = [12,78,21,22,12]*12
print(list1)
#list Iteration and Comprehension
3 in [1,2,3] #Membership
for x in [1,2,3,4,5]: #Iteration
print(x,end='')
res = [c*4 for c in 'HELLO'] # List Comprehension
print(res)
L = ['SPAN','SPAN','JAVA','PYTHON']
L[1]
#Changing Lists In-Place
#index and slice assignments
L = ['spam','Spam','SPAM']
L[1] = 'eggs' # Index assignments
print(L)
L[0:2] = ['eat','more'] #Slice assignments: delete+insert
print(L)
#List method calls
L.append('please')
L
L.sort()
''' You can modify sort behavior by passing in keyword arguments-- a special 'name=value' '''
L = ['abc','ABC','aBe']
L.sort()
L
L = ['abc','ABD','aBe'] # Normalize to lowercase
L.sort(key=str.lower)
L
#Dictionary in Action
D = {'spam':2,'ham':1,'eggs':3}
D['spam']
D['ham'] = ['grill','bake','fry'] # change entry
D ['spam'] = ['hello','java','tech']
print(D)
del D['eggs'] # delete dic.
print(D)
D['brunch'] = 'Bacon'
print(D)
list(D.items())
list(D.keys())
print(D.values())
#Update
D = {'name':'Vipin Kumar','address':'Lucknow'}
print(D)
D1 = {'phone_number':'9199922','email':'pro@12gmail.com'}
D.update(D1)