Skip to content

Instantly share code, notes, and snippets.

@whoiscarlo
Created September 9, 2014 18:06
Show Gist options
  • Save whoiscarlo/68b61a05a49f177d9a73 to your computer and use it in GitHub Desktop.
Save whoiscarlo/68b61a05a49f177d9a73 to your computer and use it in GitHub Desktop.
List comprehension
## This is the same as
arr = ['test ', 'this', ' thing ']
[x.trim() for x in arr]
## This
vals = []
for x in arr
vals.append(x.trim())
return vals
## This is the same as
[int(t) if t.isdigit() else t for t in re.split(r'(\d+)', key)]
## This
if t.isDigit():
return [int(t)]
else:
vals = []
for t in re.split(r'(\d+)', key)
vals.append(t)
return vals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment