0

I am a rank beginner, so appreciate any help. I have a list of dictionaries:

lst = [{'name': 'John', 'gender': 'Male', 'marks': [20,30,40]}, 
       {'name': 'Lynn', 'gender': 'Female', 'marks': [20,30,40,50,60]},....]

How would I convert this list into a list of tuples?. So something like:

[(John, Male, [20,30,40]), (Lynn, Female, [20,30,40,50,60]),......]

I tried this but doesn't work:

new_list = []

for dic in lst:
    new_list.append(tuple(dic.values()))

print(new_list)
richard
  • 116
  • 2
Sur Tin
  • 1
  • 1

1 Answers1

1

I like comprehension.

lst = [
    {'name': 'John', 'gender': 'Male', 'marks': [20,30,40]},
    {'name': 'Lynn', 'gender': 'Female', 'marks': [20,30,40,50,60]}
    ]

lst = [tuple(d.values()) for d in lst]

https://onlinegdb.com/Vo4PZYL7y

richard
  • 116
  • 2