Skip to content

Instantly share code, notes, and snippets.

@xdays
Last active December 15, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdays/5280451 to your computer and use it in GitHub Desktop.
Save xdays/5280451 to your computer and use it in GitHub Desktop.
a basket of python tips
#input and raw_input
def input(prompt):
return (eval(raw_input(prompt)))
#convert one-dimensional list to dictionary
dict(enumerate(list))
#bidict one-to-one mapping data structure
b = bidict(dict)
b[key]
b[value]
#print str and int one time
print 'I am ' + repr(24) + ' old'
print 'I am ' + `24` + ' old'
#dict style interpolation
print("Executing on %(host)s as %(user)s" % env)
#encoding declare
# -*- coding: UTF-8 -*-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment