Skip to content

Instantly share code, notes, and snippets.

@jocke-l
Last active December 19, 2015 17:19
Show Gist options
  • Save jocke-l/5990498 to your computer and use it in GitHub Desktop.
Save jocke-l/5990498 to your computer and use it in GitHub Desktop.
Dynamic enumration function
def enum(varnames, start=0):
return dict(zip(varnames, range(start, start + len(varnames))))
@kqr
Copy link

kqr commented Nov 20, 2013

Or

from itertools import count

def enum(start, varnames):
    return dict(zip(varnames, count(start)))

or

def enum(start, varnames):
    return { n: i for (i,n) in enumerate(varnames,start=start) }

The latter being the most Pythonic, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment