Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Turn A Flat List Into A Dictionary In Python With zip

Code

source = [
  "first_name", 
  "Alfa", 
  "middle_name", 
  "Bravo", 
  "last_name", 
  "Charlie"
]

new_dict = dict(zip(source[::2], source[1::2]))

print(new_dict)

Results

{'first_name': 'Alfa', 'middle_name': 'Bravo', 'last_name': 'Charlie'}