I have a mapping keywords like this.
categories_mapping = {
'comics': 'Comic Books',
'cartoons': 'Comic Books',
'manga': 'Comic Books',
'video and computer games': 'Video Games',
'role playing games': 'Video Games',
'immigration': 'Immigration',
'police': 'Police',
'environmental': 'Environment',
'celebrity fan and gossip': 'Celebrity',
'space and technology': 'NASA / Space',
'movies and tv': 'TV and Movies',
'elections': 'Elections',
'referendums': 'Elections',
'sex': 'Sex',
'music': 'Music',
'technology and computing': 'Technology'}
and a list like this.
labels = ['technology and computing', 'arts and technology']
I want to return the value of the dictionary if any words in the list is in the key of the dictionary.
This is what I've come up with but I think that's not very pythonic.
cats = []
for k,v in categories_mapping.items():
for l in labels:
if k in l:
cats.append(v)
return cats
The result I want is ['Technology']
Any better way of doing this?