Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wow thats so useful sarah pat urself on the back u clever kid
- #what version of python you're running
- import sys
- print("{}".format(sys.version))
- #it allows access to the indexes of the elements in a for loop (but it broke?? ? like, rude)
- blah = ['a','b','c','d','e','f']
- for (index,value) in enumerate(blahh):
- print index, value
- #flatten lists in lists
- # >> [['a', 'b'], ['c'], ['d', 'e', 'f']] into
- # >> ['a', 'b', 'c', 'd', 'e', 'f'] use
- [inner
- for outer in the_list
- for inner in outer]
- #speedup for nested lists and dictionaries
- deepcopy = lambda x: cPickle.loads(cPickle.dumps(x))
- #compile like a whole directory into a .zip file hella yeah quick backups
- import zipfile, os
- z = zipfile.ZipFile('my-archive.zip', 'w', zipfile.ZIP_DEFLATED)
- startdir = "/home/sarah"
- for dirpath, dirnames, filenames in os.walk(startdir):
- for filename in filenames:
- z.write(os.path.join(dirpath, filename))
- z.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement