0

I have two lists

teams = [ India, Australia, England ]
ratings = [ 12, 16, 11 ]

I want a dictionary like this

dict = { 'India':12, 'Australia':16, 'England':11}

I was trying to get it through looping elements of the first list, but I can't add two counters.

len1 = len(teams)
for x in range(1, len1):
    dict1[x] = rating
    print dict1

How do I create this dictionary?

Abhishek dot py
  • 909
  • 3
  • 15
  • 31

2 Answers2

1

Using dict with zip

Ex:

teams = [ 'India', 'Australia', 'England' ]
ratings = [ 12, 16, 11 ]
print(dict(zip(teams, ratings)))

Output:

{'England': 11, 'Australia': 16, 'India': 12}
Rakesh
  • 81,458
  • 17
  • 76
  • 113
0

From your original code, one counter is enough. But lists are zero indexed

for x in range(len1):
    dict1[teams[x]] = ratings[x] 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245