I need to convert a dictionary in a form {1: [‘a’, ‘b’, ‘c’, ‘d’], 2: [‘e’, ‘f’, ‘g’, ‘h’]} to a list of tuples in a form [(1, ‘a’, ‘b’, ‘c’, ‘d’), (2, ‘e’, ‘f’, ‘g’, ‘h’)]
When I try that:
dictionary = {1: [‘a’, ‘b’, ‘c’, ‘d’], 2: [‘e’, ‘f’, ‘g’, ‘h’]}
list_of_tuples = [(k, v) for k, v in dictionary.items()]
I get
list_of_tuples = [(1, [‘a’, ‘b’, ‘c’, ‘d’]), (2, [‘e’, ‘f’, ‘g’, ‘h’])]
and I need
list_of_tuples = [(1, ‘a’, ‘b’, ‘c’, ‘d’), (2, ‘e’, ‘f’, ‘g’, ‘h’)].
Zelimir_Horvat_CRO is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.