'Age-17', 42, 'MonDay'), (137, 'Age-18t', 43, 'Friday'), (140, 'Eng-1', 44, 'MonDay'), (140, 'Eng-1', 45, 'Friday')]
How way to group nested list by first element?
expect result:
[{'key': 137, values': [...]}, {'key': 140, values: [...]}]
First convert tuple into list. Then split the list. And put in as a dictionary.
Assuming this stored in a variable called data: [{'key' : item[0], 'values' : list(item[1:])} for item in data]
Обсуждают сегодня