Return a list of modified list pairs

Refresh

5 weeks ago

Views

11 time

0

Given my_list below with a list of list pairs, how do I create a new list where common element[0] values would have a list for their respective element[1] values? The order does not matter of elements from the main list does not matter.

Example

my_list = [['color', 'red'], ['length', 2], ['color', 'blue], ['shape', 'circle'], ['shape', 'square']]

return [['color', ['red', 'blue']], ['shape', ['circle', 'square']], ['length', 2]]

0 answers