-
Notifications
You must be signed in to change notification settings - Fork 0
/
coding python.py
61 lines (39 loc) · 1.17 KB
/
coding python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
list.append(var)
list.pop()
list.insert(ind, var)
list.pop(ind)
squared = list(map(lambda x: x**2, items))
less_than_zero = list(filter(lambda x: x < 0, items))
product = reduce((lambda x, y: x * y), [1, 2, 3, 4])
sorted(list, key=lambda x: x>0)
reversed(list)
def cmp(a, b):
return -1 if a < b else (1 if a > b else 0)
from functools import cmp_to_key
sorted(mylist, key=cmp_to_key(cmp))
for counter, value in enumerate(some_list):
from copy import copy, deepcopy
frozenset
all, any
from heapq import heappush, heappop, heapify
heappush(heap, item)
heappop(heap)
heap[0] # peek
yield
*:
multiply sequences
function declaration: convert varialble number of arguments into sequence (** convert named variables into dictionary)
in function call: unpack sequence into positional arguments (** unpack dictionaries into named arguments)
collections.deque
append, appendleft, pop, popleft
collections.Counter
most_common
collections.defaultdict
d = defaultdict(list) # alternatively get(val, default_val)
math.inf, math.nan
sys.maxsize
import datetime as dt
datetime.datetime(2019, 10, 11, 11, 15, 48, 164461)
delta = dt.timedelta(days=100)
compare objects:
__lt__, __eq__