Python- List, Tuples and Dictionary
#List, Tuples and Dictionary Exmaples
Lists :Like Arrays s
Mylist= [1,2,3]
Len(mylist)
Mylist[0]
Nested list
Mylist=[1,2,[3,4]]
Len(mylist)
Len(mylist[2])
Note: Mylist can be heterogeneous
Mylist.append(4)
Mylist.reverse()
Mylist.pop()
Mylist.insert(2, “aashishmittal”)
Del mylist[2]
Tuple
# used for sequence unpacking
Data=tuple(["5.5","80","aashish"])
If prints data u can check square brackets convert into round brackets it's sign of tuple
Now try
Height, weight,name= data
Sets : Unordered collection
SetA=set([1,2,3,3,2])
SetB=set([3,4,5])
SetA|setB. Union
SetA&setB. Intersection
SetA-setB. Difference
Dictionaries : un-ordered key value pair
MyBIO={'name':'aashish', 'hobby':'hacking'}
MyBIO.has_key('age’). Return true false
MyBIO.keys()
Mybio.values()
Mybio.items() return tuples
Mybio.get('hobby’)
Mybio['Location’]= ‘india’
del mybio['Location']
Mybio.clear()
Dir()# to explore more
Dir(mybio)
Help(mybio._ key)
Help(mybio.update)
Lists :Like Arrays s
Mylist= [1,2,3]
Len(mylist)
Mylist[0]
Nested list
Mylist=[1,2,[3,4]]
Len(mylist)
Len(mylist[2])
Note: Mylist can be heterogeneous
Mylist.append(4)
Mylist.reverse()
Mylist.pop()
Mylist.insert(2, “aashishmittal”)
Del mylist[2]
Tuple
# used for sequence unpacking
Data=tuple(["5.5","80","aashish"])
If prints data u can check square brackets convert into round brackets it's sign of tuple
Now try
Height, weight,name= data
Sets : Unordered collection
SetA=set([1,2,3,3,2])
SetB=set([3,4,5])
SetA|setB. Union
SetA&setB. Intersection
SetA-setB. Difference
Dictionaries : un-ordered key value pair
MyBIO={'name':'aashish', 'hobby':'hacking'}
MyBIO.has_key('age’). Return true false
MyBIO.keys()
Mybio.values()
Mybio.items() return tuples
Mybio.get('hobby’)
Mybio['Location’]= ‘india’
del mybio['Location']
Mybio.clear()
Dir()# to explore more
Dir(mybio)
Help(mybio._ key)
Help(mybio.update)