Python stdlib Flashcards
sha256 bytestring
hashlib.sha256(b’data’).digest()
sha256 hex string
hashlib.sha256(b’data’).hexdigest()
Convert unicode string to bytestring
‘string’.encode(‘utf8’)
bytes(‘string’, ‘utf8’)
Set notation
{1,2,3}
Convert a list to a set
set([1,2,3])
Insert element to set object
A.add(element)
Remove element from set object
A.remove(element)
Combine two sets
C = A.union(B)
Set subtraction
C = A.difference(B)
Get overlapping elements of two sets
C = A.intersection(B)
Insert one set into another set
A.update(B)
Create a reusable regex object
re.compile(pattern)
Single use regex call
re.match(pattern, string)
(regex) Matches start of string
(regex) Matches end of string
$
(regex) Match zero or more repetitions
*
(regex) Match one or more repetitions
+
(regex) Denotes a group within the pattern
(…)
(regex) Create a named group within the pattern
(?P<name>...)</name>
(regex) Match a set of characters
[ ]
(regex) Match 0 or 1 repetition
?
(regex) Match digit
\d
(regex) Match whitespace
\s
(regex) Match alphanumeric characters ([a-zA-Z0-9_])
\w (called “word characters”)