I have a list:
list1 = ['test', 'motor', 'mobile']
I want to create another list using items from list1 as key
and vid[key]
as value, like to output below:
list2=[
'test': vid['test'],
'motor': vid['motor'],
'mobile':vid['mobile']]
CodePudding user response:
So as I understand what you are trying to do is accept a list of strings containing individual words and for each word produce a line of output of the form "'word' = vid['word']".
To accomplish this:
for wrd in list1:
print(f"'{wrd}' = vid['{wrd}']")
Which produces:
'test' = vid['test']
'motor' = vid['motor']
'mobile' = vid['mobile']
CodePudding user response:
list2 = {}
for key in list:
list2[key] = vid[key]