10 Python One-liners To Impress Your Friends
codeblog.dhananjaynene.com
codeblog.dhananjaynene.com
Seriously though, some of these are ridiculously unreadable so think twice before using any for anything more than theory.
python -m SimpleHTTPServer python3 -m http.serverIn general, I was expecting more. I was hoping for some slightly more obscure examples, though I guess the point is that many common problems are 1 liners in Python.
[x*2 for x in range(1, 11)] [x in tweet.split() for x in wordlist]
Seems better to me than map(lambda x: x in tweet.split(),wordlist)
Although the natural thing for me to do would be [x for x in wordlist if x in tweet]
Which both generates a list of words instead of booleans(['scala', 'sbt'] instead of [True, False, False, False, False]) and also matches the 'sbt' in tweet. set(tweet.split()) & set(wordlist) 2 * numpy.arange(1, 11)
The usual notation for working with elements of vector spaces is nice when working with arrays of numbers. with open("one_liners.py") as f: print f.readlines()
In CPython, a file handle is closed immediately the file goes out of scope, because it's reference-counted. In Jython (and I believe IronPython too), with lazier garbage collection, the filehandle would stay open until it was gc'd. I have no idea about PyPy's behaviour.Very funny...
Dumb indian script kiddies... sigh