Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

list to dictionary python using for loop

list1 = [1,2,3,4]
list2 = ['one','two','three','four']

#Single List convert to Dict
my_Dict = dict()
for index, value in enumerate(list1):
    my_Dict[index] = value
print(my_Dict)

# Two list convert to dict
new_dict = dict(zip(list1,list2))
print(new_dict)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #list #dictionary #python #loop
ADD COMMENT
Topic
Name
1+1 =