This note records some hand-on tricks. Feel free to read and learn something from this article.
Unpack serialized data(if you don’t want some specific data):123456789'123', 'GOOG', 123, '123']serialized_data = [_, share, count, _ = serialized_datashare'GOOG'count123first, *many_values, last = serialized_datamany_values['GOOG', 123]
Save most recent several elements:1234567893)q = deque(maxlen=1)q.append(2)q.append(3)q.append(q[1, 2, 3]4)q.append(q[2, 3, 4]
Orderedlist used additional single linked list to store the keys.
zip()will create an iterator that could be traversed for only once.123prices_and_names = zip(prices.values(), prices.keys())# OKprint(min(prices_and_names))# ValueError: max() arg is an empty sequenceprint(max(oruces_and_names))
withstatement calls the
__enter__()function when evaluating the expression or entering the with block and it assigns the return value to the variable after
askeyword. When the codes go out of the
withstatement, the codes will call
__exit__()function even though an exception is raised.
Functions in Python are actually objects. Function has
id. They can be passed as an parameter or assigned to other variable.