×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Matthew J_
Added: Jun 22, 2022 10:56 PM
Modified: Jun 22, 2022 11:09 PM
Views: 8
Tags: no tags
  1. # Combine 2 lists to correspond key, value to make a new dict
  2.  
  3. def list_to_dictionary(keys, values):
  4.   return dict(zip(keys, values))
  5.  
  6. list1 = [1, 2, 3]
  7. list2 = ['one', 'two', 'three']
  8.  
  9. combined_dict = (list_to_dictionary(list1, list2))
  10.  
  11. print(combined_dict)        # {1: 'one', 2: 'two', 3: 'three'}