30秒学会 Python 片段 – collect_dictionary
Inverts a dictionary with non-unique hashable values. Use dictionary.items() in combination with a l...
Inverts a dictionary with non-unique hashable values. Use dictionary.items() in combination with a l...
Splits values into two groups according to a function, which specifies which group an element in the...
Removes falsey values from a list. Use filter() to filter out falsey values (False, None, 0, and “”)...
Returns a list of elements that exist in both lists. Create a set from a and b, then use the built-i...
Casts the provided value as a list if it’s not one. Use isinstance() to check if the given val...
Merges two or more dictionaries. Create a new dict() and loop over dicts, using dictionary.update() ...
Returns the symmetric difference between two iterables, without filtering out duplicate values. Crea...
Returns the transpose of a two-dimensional list. Use *lst to get the passed list as tuples. Use zip(...
Converts a string to camelcase. Use re.sub() to replace any – or _ with a space, using the regexp r”...
Converts a string to snake case. Break the string into words and combine them adding _ as a separato...