0

These are the 2 lists I am trying to use:

names = ['joe', 'tom', 'barb', 'sue', 'sally']
scores = [10, 23, 13, 18, 12]

and I'm using a function I created named makeDictionary with the parameters (list1, list2).

I do not want a direct answer in code, but how would I make the names list the keys in the dictionary, and the scores list the values in the dictionary?

Example output dictionary:

{'joe': 10, 'tom': 23, 'barb': 13, 'sue': 18, 'sally': 12}
Selcuk
  • 52,758
  • 11
  • 94
  • 99
dorlox
  • 75
  • 7

2 Answers2

2

This is what zip is for:

>>> dict(zip(names, scores))
{'joe': 10, 'tom': 23, 'barb': 13, 'sue': 18, 'sally': 12}
Selcuk
  • 52,758
  • 11
  • 94
  • 99
2

You may simply do:

dict(zip(names,scores))

Output

{'joe': 10, 'tom': 23, 'barb': 13, 'sue': 18, 'sally': 12}
Sebastien D
  • 4,181
  • 4
  • 16
  • 43