Python Inbuilt Functions and Imports - Cheat Sheet
1. Input/Output Functions
-------------------------
input() - take user input as string
print() - display output
2. Type Conversion
------------------
int(), float(), str(), list(), tuple(), set()
3. Math Functions (from math import ...)
----------------------------------------
from math import sqrt, ceil, floor, pow, factorial, gcd
Examples:
sqrt(25) -> 5.0
ceil(2.3) -> 3
floor(2.9) -> 2
pow(2, 3) -> 8.0
factorial(5) -> 120
gcd(12, 15) -> 3
4. String Methods
-----------------
lower(), upper(), strip(), split(), join(), replace(), isdigit(), isalpha()
5. List Methods
---------------
append(), extend(), insert(), remove(), pop(), sort(), reverse(), count(), index()
6. Set Methods
--------------
add(), remove(), union(), intersection(), difference()
7. Dictionary Methods
---------------------
keys(), values(), items(), get(), update()
8. Utility Built-ins
--------------------
len(), max(), min(), sum(), sorted(), reversed(), range()
9. Useful Imports (from __ import __)
-------------------------------------
from math import sqrt, ceil, gcd, factorial
from itertools import permutations, combinations, product
from collections import Counter, defaultdict, deque
from functools import reduce
from heapq import heappush, heappop, heapify
from random import randint, choice, shuffle
from string import ascii_lowercase, ascii_uppercase, digits
Examples:
Counter("banana") -> {'b':1, 'a':3, 'n':2}
list(permutations("abc", 2)) -> [('a','b'),('a','c'), ...]
reduce(lambda x,y: x*y, [1,2,3]) -> 6
heapify([3,1,2]); heappop() -> 1
choice([1,2,3]) -> random value from list
ascii_lowercase -> 'abcdefghijklmnopqrstuvwxyz'