Python stdlib Flashcards

1
Q

sha256 bytestring

A

hashlib.sha256(b’data’).digest()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

sha256 hex string

A

hashlib.sha256(b’data’).hexdigest()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Convert unicode string to bytestring

A

‘string’.encode(‘utf8’)
bytes(‘string’, ‘utf8’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Set notation

A

{1,2,3}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Convert a list to a set

A

set([1,2,3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Insert element to set object

A

A.add(element)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Remove element from set object

A

A.remove(element)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Combine two sets

A

C = A.union(B)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Set subtraction

A

C = A.difference(B)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Get overlapping elements of two sets

A

C = A.intersection(B)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Insert one set into another set

A

A.update(B)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Create a reusable regex object

A

re.compile(pattern)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Single use regex call

A

re.match(pattern, string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

(regex) Matches start of string

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

(regex) Matches end of string

A

$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(regex) Match zero or more repetitions

A

*

17
Q

(regex) Match one or more repetitions

A

+

18
Q

(regex) Denotes a group within the pattern

A

(…)

19
Q

(regex) Create a named group within the pattern

A

(?P<name>...)</name>

20
Q

(regex) Match a set of characters

A

[ ]

21
Q

(regex) Match 0 or 1 repetition

A

?

22
Q

(regex) Match digit

A

\d

23
Q

(regex) Match whitespace

A

\s

24
Q

(regex) Match alphanumeric characters ([a-zA-Z0-9_])

A

\w (called “word characters”)