Can I put two Python lists in the dictionary's key and value values?

Asked 2 years ago, Updated 2 years ago, 160 views

Can I put two lists in one dictionary as keys and values?

a=["Apple", "Banana", "Pineapple"] b=[1,2,3] When

dic={'Apple':1, 'Banana':2, 'Pineapple':3}

Can you put it in order like this?

dictionary list key value python

2022-09-22 16:08

1 Answers

You can use the zip.

dic = { name:value for name, value in zip(a, b) }


2022-09-22 16:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.