I have a for loop which outputs a list of 15 values:
for line in data:
line # type(line) is `<class 'list'>`
# do things with line
This line
is always a Python list of 11 values, i.e.
['value1', 'value2', 'value3', 'value4', ... ]
I have a list of dictionary keys, which I have manually created:
['key1', 'key2', 'key3', ...]
I would like to join my keys to each of the values for each line in my for loop. Therefore, I can define a new line that looks like
['key1': 'value1', 'key2': 'value2', 'key3': 'value3', ... ]
This would be used in the for loop, i.e.
for line in data:
line # values
# join key-value pairs
# new_line = ['key1': 'value1', 'key2': 'value2', 'key3': 'value3', ... ]
# do things with new_line
EDIT: I don't believe this is a repeat question. zip(keys, values)
does not produce the desired result.
EDIT2: Would it be easier to create one large dictionary within a list?
[{'key1': 'value1', 'key2': 'value2', 'key3': 'value3', ... }]
or perhaps a tab-delimited test file?
key1:value1 key2:value2 key3:value3 ....