A dictionary comprehension makes short work of this task:
>>> s = [['A','B','C','D'], ['B','E','F'], ['C','A','B','D'], ['D']]
>>> {t[0]:t[1:] for t in s}
{'A': ['B', 'C', 'D'], 'C': ['A', 'B', 'D'], 'B': ['E', 'F'], 'D': []}
More Related Contents:
- I don’t know how to display step 3 for this assignment
- How to make a dict from n’th indices of tuples in list
- Access a particular field in arbitrarily nested JSON data [duplicate]
- Remove duplicate dict in list in Python
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- list to dictionary conversion with multiple values per key?
- How to overcome TypeError: unhashable type: ‘list’
- How can I convert a dictionary into a list of tuples?
- List of dicts to/from dict of lists
- Appending a dictionary to a list – I see a pointer like behavior
- merging Python dictionaries
- How can I initialize a dictionary of distinct empty lists in Python?
- List of tuples to dictionary [duplicate]
- [] and {} vs list() and dict(), which is better?
- Converting Dictionary to List? [duplicate]
- How to find the min/max value of a common key in a list of dicts?
- Converting a list of tuples into a dict
- Appending a dictionary to a list in a loop
- One liner: creating a dictionary from list with indices as keys
- Group by multiple keys and summarize/average values of a list of dictionaries
- Get a list of values from a list of dictionaries?
- How do I sort this list in Python, if my date is in a String?
- How do I extract all the values of a specific key from a list of dictionaries?
- What are dict_keys, dict_items and dict_values?
- How do I send list of dictionary as Body parameter in FastAPI?
- Python The appended element in the list changes as its original variable changes
- How to sort a list of dictionaries by a value of the dictionary in Python?
- How to extract all values from a dictionary in Python?
- Comparing 2 lists consisting of dictionaries with unique keys in python
- How to create a nested dictionary from a list in Python?