-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList_Dict_Sets.py
62 lines (46 loc) · 1.31 KB
/
List_Dict_Sets.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
""" DATA TYPES are SIX """
# NUMBERS
# STRINGS
# TUPLES
# LISTS
# DICTIONARY
# SETS
## LIST - Can be modified ... used with [ ]
pyList = ['Rajat', 'Shubham', 'Sanket']
# APPEND
pyList.append('Swapnil')
print(pyList)
#EXTEND
pyList.extend(['Suraj', 'Vaibhav'])
print(pyList)
#INSERT
pyList.insert(3, 'Arsh')
print(pyList)
#POP
pyList.pop()
print(pyList)
## DICTIONARY... used as key-value pair...{ }
myDictionary = {533:'Rajat', 532:['Diksha', 'priyanka'], 528:'Swapnil', 540:'Pooja', 538:'Vaibhav'}
print(myDictionary[528])
print(len(myDictionary)) #no. of key value pairs
print(myDictionary.keys()) # keys are printed
print(myDictionary.values()) #values are printed
print(myDictionary.items()) #saperate key-values pairs are printed
print(myDictionary.get(532)) #values at specified key are printed
myDictionary.update({581:'Mayuri'}) # adds key-values to the DICTIONARY
print(myDictionary)
### SETS ####
# A set is an unordered collection of items
# Every element is unique and can not be changed
# Repeated values are shown just onces
firstSet = {'Rajat', 'Swapnil', 'Diksha', 'Pooja'}
secondSet = {'Rajat', 'Sanket', 'Shubham', 'Vaibhav'}
print(firstSet)
# OPERATIONS
# UNION
print(firstSet | secondSet)
# INTERSECTION
print(firstSet & secondSet)
# DIFFERENCE
print(firstSet - secondSet)
print(secondSet - firstSet)