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):
'123', 'GOOG', 123, '123']serialized_data = [
_, share, count, _ = serialized_data
first, *many_values, last = serialized_data
Save most recent several elements:
3)q = deque(maxlen=
[1, 2, 3]
[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.
prices_and_names = zip(prices.values(), prices.keys())
# 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.