from operator import itemgetter
params = {'a': 1, 'b': 2}
a, b = itemgetter('a', 'b')(params)
Instead of elaborate lambda functions or dictionary comprehension, may as well use a built in library.
More Related Contents:
- How do I sort a dictionary by value?
- How do I sort a list of dictionaries by a value of the dictionary?
- How to keep keys/values in same order as declared?
- How can I sort a dictionary by key?
- How to sort objects by multiple keys?
- Sorting a dictionary by value then key
- heapq with custom compare predicate
- How does the key argument in python’s sorted function work?
- How do I sort a dictionary by key?
- Sorting a dictionary with lists as values, according to an element from the list
- Sort nested dictionary by value, and remainder by another value, in Python
- In Python, how do I iterate over a dictionary in sorted key order?
- How to sort IP addresses stored in dictionary in Python?
- How to sort dictionary by key in numerical order Python
- Right way to initialize an OrderedDict using its constructor such that it retains order of initial data?
- Sort a list of tuples by second value, reverse=True and then by key, reverse=False
- sorting list of nested dictionaries in python
- How to sort a list of dictionaries by a value of the dictionary in Python?
- How to name a file using a value in a list in a dictionary?
- Why is dictionary ordering non-deterministic?
- Object of custom type as dictionary key
- Python: sort function breaks in the presence of nan
- List sorting with multiple attributes and mixed order
- Elegant way to remove fields from nested dictionaries
- python: read json and loop dictionary
- Python: use mysqldb to import a MySQL table as a dictionary?
- Pythonic way to sorting list of namedtuples by field name
- Python dictionary comprehension using locals() gives KeyError
- How to extract all values from a dictionary in Python?
- Comparing 2 lists consisting of dictionaries with unique keys in python