565 connected_condition.notify_all()
566
567
568def clean_alphanumeric(str):569 return re.sub('[^0-9a-zA-Z.]+', '-', str)
570
571
17
18 for token in tokens:
19 try:
20 type, data = token.split(' ', 2)21 items = data.split(';')
22
23 if len(items) == 0:
14def compress_data(data):
15 try:
16 encoded = data.encode('utf-8')
17 bytes = gzip.compress(encoded)18 return str(base64.b64encode(bytes), 'utf-8')
19 except AttributeError:
20 return data.encode('zlib')
4
5def decompress_data(value):
6 try:
7 bytes = base64.b64decode(value) 8 data = gzip.decompress(bytes)
9 return data.decode('utf-8')
10 except AttributeError:
36 return ''.join(random.choice(allowed_chars) for i in range(length))
37
38
39def find_index(list, predicate): 40 for i, value in enumerate(list):
41 if predicate(value, i):
42 return i
Defining a local variable or function with the same name as a built-in object makes the built-in object unusable within the current scope and makes the code prone to bugs.
dict = {} # dict is a Python builtin!
for idx, student in enumerate(students):
dict[student] = idx
roll_number = {}
for idx, student in enumerate(students):
roll_number[student] = idx