-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastructure.py
83 lines (49 loc) · 1.16 KB
/
datastructure.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
75
76
77
78
79
80
81
82
83
#List
#------------------------
# A list is an ordered collection of values
# list is mutable
b=[10,20]
nested = ["hello",2.0, 5, [10,20]]
print ( b[0])
print ( nested[3][1])
# possible operations
# concatenations
# memberships
# for loop
print ( 3 in [1,2,3])
print ( ['hi'] * 4 ) # repeated in single list
# append, extend, pop , reverse, sort
c=[1,2]
print ( c)
# Tuple
#------------------------
# tuple is immutable
rec=("ruck",1235,10.5)
print ( rec)
print (type(rec))
# basic operations
# unpack
# swap
for x in (1,2,3):
print ( (x))
# min, max
#Dictionary
#------------------------
# key value pair
# its mutable but keys immutable
dic = {'one': 'value','two':'value','three': None}
dic2 = {'four' : 'value'}
dic.update(dic2)
if dic['three'] == None : # not "None"
print ("true its none ")
print (dic.keys())
print ( dic)
# SETS
#-------------------
# its a container to store unique elements
# for null or empty in other technologies but in python its none
basket=['apple', 'banana','apple']
fruit = set(basket)
print ( fruit)
# operations
# in, not in