Last active
August 29, 2015 14:00
-
-
Save vxf/bb7ff11080603bcbdd6f to your computer and use it in GitHub Desktop.
python magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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