I have a list of dicts which I would like to filter with another list, but am having trouble with the filter() function
list_of_dicts = [{'name': 'Bob'},{'name': 'Alice'},{'name':'Jenny'}]list_2 = ['Bo', 'Alic']# filter(lambda name: any(list2) in list_of_dicts['name'], list_of_dicts)Ideally, I would want above to return:[{'name': 'Bob'},{'name': 'Alice'}]or the converse# filter(lambda name: any(list_2) not in list_of_dicts['name'], list_of_dicts)[{'name':'Jenny'}]The requirement here is that I use the filter() function. Additionally, I am trying to see if list2 is contained as a substring of the list_of_dicts['name']
Cell In[8], line 1, in <lambda>(name)----> 1 list(filter(lambda name: any(list_2) in list_of_dicts['name'], list_of_dicts))TypeError: list indices must be integers or slices, not str