0

I'm relatively new to Python and are currently stuck at a project.

To be more specific. I have two list of strings, and want them to link in the following way:

list1 = ["P1", "P2", "P3" ]

list2 = ["1", "2","3" ]

but, I want this

P1 = 1

P2 = 2

etc.

How do I solve this?

losusovic
  • 608
  • 5
  • 22
tshk94234
  • 27
  • 1

1 Answers1

5

Create dictionary by zip:

d = dict(zip(list1,list2))
print (d)
{'P3': '3', 'P2': '2', 'P1': '1'}

#select by keys
print (d['P1'])
1

print (d['P2'])
2
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252