Tuesday, December 25, 2012

Python dictionary and zip


  1. len(myDict)
  2. eletment in myDict
  3. for key in myDict:
  4. for key in myDict.keys()
  5. for key, value in myDict.items():
  6. for value in myDict.values():

  1. myDict,ckear()
  2. aDict,update(bDict) - for each key in bDict, updates aDict with that key/value pair

zip() is the built-in function
  1. zip("abc", [1, 2, 3])  --> [(‘a’,1),(‘b’,2),(‘c’,3)] 
  2. dict(zip("abc", [1, 2, 3]) -->{'a': 1, 'c': 3, 'b': 2} 

aString = "\n".join(aList)
aList = aString.split("\n")

OrderedDict
reports = collections.OrderedDict()
the OrderedDict will remember the sequence of key insertion

No comments:

Post a Comment