Wednesday, November 9, 2016



How do you create a dictionary with keys and values from two different lists?

We can use the zip built-in function to stitch the lists and then pass it to the dict constructor to build a dictionary.


Note that the zip function doesn't return a list in python 3.x instead it returns a zip object reference which can be passed to the list and tuple constructors to create a list and tuple respectively. In python 2.x however, it returns a list.

                  In 3.5.1
               
          In 2.7.12  





No comments:

Post a Comment