how do i make a dictionary out of consecutive elements in a list?

Try this.

numbers = ['Joe', '123-5432', 'Linda', '983-4123', 'Frank', '867-5309']
d = {numbers[i]:numbers[i+1] for i in range(0, len(numbers), 2)}
print(d)
{'Joe': '123-5432', 'Linda': '983-4123', 'Frank': '867-5309'}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top