Answer the question
In order to leave comments, you need to log in
How to combine two lists into a dictionary?
Good afternoon, there are two lists that need to be added to the dictionary
timestamp = [11111,22222,33333]
file_list = ['file1','file2','file3']
for file_time_created in file_list:
files_dict = [ {'key':file_time_created, 'value': timestamp} ]
print(files_dict)
[{'key': 'file1', 'value': 11111}]
[{'key': 'file1', 'value': 11111},{'key': 'file2', 'value': 22222},{'key': 'file3', 'value': 33333}]
Answer the question
In order to leave comments, you need to log in
Declare a dictionary before the loop. In the loop, call the append method of your dictionary.
timestamp = [11111,22222,33333]
file_list = ['file1','file2','file3']
files_dict = [{"key":k, "value":file_list[i]} for i,k in enumerate(timestamp)]
files_dict = dict(zip(timestamp, file_list))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question