Python - Create dictionaries via dict and zip function


We can make dictionaries by passing to the dict type name either keyword arguments, or the result of zipping together sequences of keys and values obtained at runtime.

Both the following make the same dictionary:


bob1 = dict(name='Bob', job='dev', age=40)                      # Keywords 
print( bob1 )
bob2 = dict(zip(['name', 'job', 'age'], ['Bob', 'dev', 40]))    # Zipping 
print( bob2 )


Mappings are not ordered.

Related Topic