python -c “print reduce(lambda x,y:x+y,zip(range(0,10,2),range(1,10,2)))”
Tag Archives: python
Python 2 print headers and content of url
python -c 'import urllib2; resp = urllib2.urlopen("http://localhost:10888/cgi-bin/hello.py"); print resp.info(), resp.read()'
Python 3 print headers and content of url
python3 -c 'import urllib.request; resp = urllib.request.urlopen("http://localhost:10888/cgi-bin/hello.py"); print(resp.info(), resp.read().decode("utf-8"))'
Python 3 CGI web server with cgi-bin directory
python3 -c 'import http.server; http.server.HTTPServer(("", 10888), http.server.CGIHTTPRequestHandler).serve_forever()'
Python cgi web server with cgi-bin and htbin
python -m CGIHTTPServer 10080
Python 3 web server the current directory
python3 -m http.server 10030
Python web server the current directory
python -m SimpleHTTPServer 10080
Python as a shell
ipython -p pysh
Reversing a string in python – version special case
python -c 'print "The rain in spain."[::-1]'
Reversing a string in python – version after sleeping on it
python -c 'print "The rain in spain."[-1::-1]'
Reversing a string in python – version the first
python -c 's = "The rain in spain falls mainly on the plain."; print "".join(s[c] for c in xrange(len(s) - 1, -1, -1))'
python list sort
python -c 'x=["hello","my","friend"];x.sort();print x'
python one liners start with -c
python -c 'hw=[x for x in "hello world".title().partition()];x=len(hw);(x*"%s"+"!")%tuple(hw)'