Created
May 28, 2012 09:28
-
-
Save judy2k/2818140 to your computer and use it in GitHub Desktop.
This file contains 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
# Theirs: | |
print map(lambda x: x * 2, range(1,11)) | |
# Mine: | |
print [x*2 for x in range(1,11)] |
This file contains 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
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] |
This file contains 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
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)] |
This file contains 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
# 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