Is there a way I can use list comprehension answered in this thread to create dictionary?
listA = [
"apple_v001",
"apple_v002",
"banana_v001",
"orange_v001",
]
keywords = ["apple", "banana", "orange"]
[[item for item in listA if kw in item] for kw in keywords]
# Result: [['apple_v001', 'apple_v002'], ['banana_v001'], ['orange_v001']] #
What I'm trying to do is create a dictionary using keywords as key out of this result. So
dictA["apple"] = ['apple_v001', 'apple_v002']
and so forth. I tried to do the dict = {key, value for ...(iteration) } but always get a syntax error. I really don't know how to start, any help appreciate.