After 10 Scala / Ruby / Clojure / CoffeeScript one liners to impress your friends, i thought it might be interesting to quickly try out the same in Python too.
Without much ado.. here goes. Note that the variable declarations and imports are on separate lines as necessary. Also every line is written so as to print out the results to stdout for quick verification
For what it is worth, this hardly took any time - this post is probably one of the quickest I have written.
1. Multiple Each Item in a List by 2
2. Sum a List of Numbers
3. Verify if Exists in a String
wordlist=["scala","akka","play framework","sbt","typesafe"]tweet="This is an example tweet talking about scala and sbt."printmap(lambdax:xintweet.split(),wordlist)
4. Read in a File
5. Happy Birthday to You!
printmap(lambdax:"Happy Birthday to "+("you"ifx!=2else"dear Name"),range(4))
fromxml.dom.minidomimportparse,parseStringimporturllib2# note - i convert it back into xml to pretty print itprintparse(urllib2.urlopen("http://search.twitter.com/search.atom?&q=python")).toprettyxml(encoding="utf-8")