0

I want to merge two lists into list(tuple()) here's example

['robin', 'kate', 'shim', 'help'] # this was originally dictionary keys

with:

[100, 200, 300, 400, 500] # this was originally dictionary values

into:

[('robin', 100), ('kate', 200), ...]

I need some solutions please help me

  • 1
    Alternatively, you might want to cast the output of `dict.items()` into a `list`, i.e. `list(dict.items())`. – metatoaster May 10 '21 at 00:53
  • The simplest is from a dictionary as the previous comment mentions. But, if you have names and scores separately you can use: ` [(name, score) for name, score in zip(names, scores)]` to generate the desired list of tuples. – DarrylG May 10 '21 at 01:00
  • @DarrylG or just `list(zip(names, scores))` to follow the easiest to write version as noted through the linked thread. – metatoaster May 10 '21 at 02:36
  • @metatoaster--good point on just `list(zip(names, scores))` – DarrylG May 10 '21 at 03:00

0 Answers0