Watch out for mutable default arguments in Python
Mutable default arguments can trip up Python beginners and veterans alike. Here's a quick workaround to deal with them.
The Python snippet collection contains helper functions for Python 3.6. It includes utilities for most common data types, such as primitivies, lists, dictionaries and date objects.
Mutable default arguments can trip up Python beginners and veterans alike. Here's a quick workaround to deal with them.
Maps the values of a list to a dictionary using a function.
Retrieves the value of the nested key indicated by the given selector list from a dictionary or list.
Finds the index of the last element in the given list that satisfies the provided testing function.
Finds the index of the first element in the given list that satisfies the provided testing function.
Finds the indexes of all elements in the given list that satisfy the provided testing function.
Converts a number to a list of digits.
Splits values into two groups, based on the result of the given filter
list.
Returns the sum of the powers of all the numbers from start
to end
(both inclusive).
Using str.lstrip()
to strip a prefix from a string might not be exactly what you're looking for. Here's what you should use instead.
Converts the values of RGB components to a hexadecimal color code.
Converts a list of dictionaries into a list of values corresponding to the specified key
.
Understand Python's named tuples and start using them in your projects today.
Learn how Python's lists and tuples are different and level up your code today.
Checks if the a value is an empty sequence or collection.
Learn two ways to format a string in Python with this quick tip.
Finds the value of the first element in the given list that satisfies the provided testing function.
Finds the items that are parity outliers in a given list.
Finds the value of the last element in the given list that satisfies the provided testing function.
Chunks a list into n
smaller lists.
Converts an integer to its roman numeral representation. Accepts value between 1
and 3999
(both inclusive).
Learn how to sort a Python dictionary list using a tuple key.
Merges two or more dictionaries.
Inverts a dictionary with unique hashable values.