Python

To upgrade pip

python -m pip install --upgrade pip

Install a library

$ pip install requests
$ pip install lib_name;

Define list – some cool ways

>>> s = [x ** 2 for x in range(10) ]
>>> s
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> s = [x ** 2 for x in range(10) if x % 2]
>>> s
[1, 9, 25, 49, 81]
>>> s = [x ** 2 for x in range(10) if not x % 2]
>>> s
[0, 4, 16, 36, 64]

Download a web page

from bs4 import BeautifulSoup
import urllib.request
data = urllib.request.urlopen('https://ora600tom.wordpress.com/2014/11/21/append-and-parallel/').read()
soup = BeautifulSoup(data)

 

Advertisements
%d bloggers like this: