Try:
>>> t = ((1, 'a'),(2, 'b'))
>>> dict((y, x) for x, y in t)
{'a': 1, 'b': 2}
More Related Contents:
- Why can’t I use a list as a dict key in python?
- List of tuples to dictionary [duplicate]
- Converting a list of tuples into a dict
- Convert a namedtuple into a dictionary
- Why can’t I use a list as a dict key in python? Exactly what can and cannot be used, and why?
- Converting a csv file into a list of tuples with python
- In what case would I use a tuple as a dictionary key? [closed]
- Function to return results in a dictionary in Python
- Convert a String representation of a Dictionary to a dictionary?
- Why dict.get(key) instead of dict[key]?
- Remove duplicate dict in list in Python
- How to get a random value from dictionary?
- list to dictionary conversion with multiple values per key?
- Converting Python dict to kwargs?
- Explicitly select items from a list or tuple
- count the number of occurrences of a certain value in a dictionary in python?
- Transform “list of tuples” into a flat list or a matrix
- Convert RGB color to English color name, like ‘green’ with Python
- TypeError: ‘dict_keys’ object does not support indexing
- 5 maximum values in a python dictionary
- Make dictionary from list with python [duplicate]
- Using a Python Dictionary as a Key (Non-nested)
- How do I return dictionary keys as a list in Python?
- Python dictionary replace values
- How to get multiple dictionary values?
- Sort a list of tuples by second value, reverse=True and then by key, reverse=False
- python dict.add_by_value(dict_2)?
- Filter a list of tuples based on condition
- How do I merge dictionaries together in Python?
- Python: Writing Nested Dictionary to CSV