-1

I have 2 lists:

name = ["Stirling","Lana","Cyril","Pam","Ray","Cheryl"]

alias =["Duchess","Truckasaurus","Chet","Cookie Monster","Gilles de Rais","Cherlene"]

I need to create a dictionary such that the name is the key and alias is the value, in this particular way:

Stirling : Duchess

Also I have to use the for loop to do so.

llllllllll
  • 16,169
  • 4
  • 31
  • 54
C. Kamath
  • 3
  • 1
  • 4
  • Perhaps `my_dict = dict(zip(name, alias))`, but please explain why you must use a `for` loop. – Robᵩ Mar 23 '18 at 15:18

1 Answers1

1

You can simply zip them.

name = ["Stirling","Lana","Cyril","Pam","Ray","Cheryl"]

alias =["Duchess","Truckasaurus","Chet","Cookie Monster","Gilles de Rais","Cherlene"]

my_dict = dict(zip(name, alias))
Mike Tung
  • 4,735
  • 1
  • 17
  • 24
  • Thats right but what if I have to make use of a for statement for eg: for i in range(0,len(name)): #Add pairs to the dictionary from the lists for Loop through sorted dictionary: #Print item and value – C. Kamath Mar 23 '18 at 15:50