Python stdlib Flashcards
1
Q
sha256 bytestring
A
hashlib.sha256(b’data’).digest()
2
Q
sha256 hex string
A
hashlib.sha256(b’data’).hexdigest()
3
Q
Convert unicode string to bytestring
A
‘string’.encode(‘utf8’)
bytes(‘string’, ‘utf8’)
4
Q
Set notation
A
{1,2,3}
5
Q
Convert a list to a set
A
set([1,2,3])
6
Q
Insert element to set object
A
A.add(element)
7
Q
Remove element from set object
A
A.remove(element)
8
Q
Combine two sets
A
C = A.union(B)
9
Q
Set subtraction
A
C = A.difference(B)
10
Q
Get overlapping elements of two sets
A
C = A.intersection(B)
11
Q
Insert one set into another set
A
A.update(B)
12
Q
Create a reusable regex object
A
re.compile(pattern)
13
Q
Single use regex call
A
re.match(pattern, string)
14
Q
(regex) Matches start of string
A
15
Q
(regex) Matches end of string
A
$