-2

I have a requirement to convert two list into a dictionary. Just wondering if there is an easiet and pythonic way of doing it.

i can acheive that using the code below but wanted to know if this is the right way of doing it

a = ['1.1.1.1','1.1.1.2']
b = ['225.1.1.1','225.1.1.2']
d = {}
for i,j in enumerate(a):
    d[j]= b[i]

print(d)
VijayS
  • 81
  • 4
  • It looks like you're pairing IPv4 addresses. Are you sure lists will always be the same length? can a single key (from `a` list) be paired with differents values (from `b` list) or viceversa? – Gsk Jan 28 '20 at 12:20

1 Answers1

2

Use zip,

a = ['1.1.1.1','1.1.1.2']
b = ['225.1.1.1','225.1.1.2']
dict(zip(a,b))
Shibiraj
  • 769
  • 4
  • 9