Python Forum

Full Version: search for more than one word using lambda
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have this code:
sga = list(filter(lambda x: 'costs' in x, income.index))
trying to grab all index labels with the word 'costs' in it but I want to add another word to include in this grab. So for example, grab all labels that have either 'costs' or 'administrative'

I can't seem to figure it out or find it anywhere.

Any help would be appreciated.

Matt
words = ['costs', 'administrative']
sga = [index for index in income.index if any(w in index for w in words)]
(Nov-12-2020, 08:42 PM)bowlofred Wrote: [ -> ]
words = ['costs', 'administrative']
sga = [index for index in income.index if any(w in index for w in words)]

thanks! this did the trick.