Skip to content

Instantly share code, notes, and snippets.

@vxf
Last active August 29, 2015 14:00
Show Gist options
  • Save vxf/bb7ff11080603bcbdd6f to your computer and use it in GitHub Desktop.
Save vxf/bb7ff11080603bcbdd6f to your computer and use it in GitHub Desktop.
python magic
# flaten a list of lists
[y for x in list for y in x]
# transform month to int
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Oct', 'Sep', 'Nov', 'Dec'].index(m) + 1
# generate part of a slug from a name
slug = re.sub('[^\w\d]+', '-', name).strip('-').lower()
# check if it's a sequence (of numbers)
l[1:] == [i + 1 for i in l[:-1]]
# list inversion
l[::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment