python list | tuple | set | dictionery

Lists
Mylist= [1,2,3]
Len(mylist)
Mylist[0]
Nested list
Mylist=[1,2,[3,4]]
Len(mylist)
Len(mylist[2])
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 myBiocollection
SetA=set([1,2,3,3,2])
SetB=set([3,4,5])
SetA|setB.  Union
SetA&setB.  Intersection
SetA-setB.  Difference

Dictionaries 
#unordered  value pair
MyBio={'name':'aashish', 'hobby':'hacking'}
myBio
print MyBio.has_key("age") #.  Return true false
print MyBio.keys()
print MyBio.values()
print MyBio.items()# return tuples
print MyBio.get("hobby")
MyBio["Location"]= "india"
print MyBio.has_key("Location")
del MyBio['Location']
print MyBio.has_key("Location")
MyBio.clear()del
print MyBio.keys()
print MyBio.values()
#dir()# to explore more
print dir(MyBio)
Help(mybio._ key)
Help(mybio.update)

Reactions:

0 comments:

Post a Comment