Advertisement
tinypirate

wow thats so useful 10/10 ign

May 30th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. wow thats so useful sarah pat urself on the back u clever kid
  2.  
  3. #what version of python you're running
  4. import sys
  5. print("{}".format(sys.version))
  6.  
  7. #it allows access to the indexes of the elements in a for loop (but it broke?? ? like, rude)
  8. blah = ['a','b','c','d','e','f']
  9. for (index,value) in enumerate(blahh):
  10.     print index, value
  11.  
  12. #flatten lists in lists
  13. # >> [['a', 'b'], ['c'], ['d', 'e', 'f']] into
  14. # >> ['a', 'b', 'c', 'd', 'e', 'f'] use
  15. [inner
  16.     for outer in the_list
  17.         for inner in outer]
  18.  
  19. #speedup for nested lists and dictionaries
  20. deepcopy = lambda x: cPickle.loads(cPickle.dumps(x))
  21.  
  22. #compile like a whole directory into a .zip file hella yeah quick backups
  23. import zipfile, os
  24. z = zipfile.ZipFile('my-archive.zip', 'w', zipfile.ZIP_DEFLATED)
  25. startdir = "/home/sarah"
  26. for dirpath, dirnames, filenames in os.walk(startdir):
  27.   for filename in filenames:
  28.     z.write(os.path.join(dirpath, filename))
  29. z.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement