Skip to content

Instantly share code, notes, and snippets.

@seantalts
Created November 8, 2011 16:54
Show Gist options
  • Save seantalts/1348350 to your computer and use it in GitHub Desktop.
Save seantalts/1348350 to your computer and use it in GitHub Desktop.
import time
input = ['a', 'b', 'c', 'd', 'e', 'f']
iterations = 1000000
start = time.time()
for i in xrange(iterations):
s = dict([(x.lower(), i) for i, x in enumerate(input)])
end = time.time()
print "First thing took %s seconds" % (end - start)
start = time.time()
for i in xrange(iterations):
s = dict((x.lower(), i) for i, x in enumerate(input))
end = time.time()
print "second thing took %s seconds" % (end - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment