Skip to content

Instantly share code, notes, and snippets.

@judy2k
Created May 28, 2012 09:28
Show Gist options
  • Save judy2k/2818140 to your computer and use it in GitHub Desktop.
Save judy2k/2818140 to your computer and use it in GitHub Desktop.
# Theirs:
print map(lambda x: x * 2, range(1,11))
# Mine:
print [x*2 for x in range(1,11)]
wordlist = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."
# Theirs:
print map(lambda x: x in tweet.split(),wordlist)
# Mine:
print [x in tweet.split() for x in wordlist]
print map(lambda x: "Happy Birthday to " + ("you" if x != 2 else "dear Name"),range(4))
print ["Happy Birthday to " + ("you" if x != 2 else "dear Name") for x in range(4)]
# Theirs:
print reduce(lambda(a,b),c: (a+[c],b) if c > 60 else (a,b + [c]), [49, 58, 76, 82, 88, 90],([],[]))
# Not quite equivalent, but kinda fun (I love zip):
zip((i if i <= 60 else None, i if i > 6 else None) for i in [49, 58, 76, 82, 88, 90])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment