Python Forum
search for more than one word using lambda
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
search for more than one word using lambda
#1
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
Reply
#2
words = ['costs', 'administrative']
sga = [index for index in income.index if any(w in index for w in words)]
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Complex word search multiple files Kristenl2784 0 521 Jul-18-2020, 01:22 PM
Last Post: Kristenl2784
  Partial Word Search Kristenl2784 2 653 Jun-29-2020, 08:26 PM
Last Post: Kristenl2784
  Python Speech recognition, word by word AceScottie 6 10,588 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 1,618 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  Linear search/searching for a word in a file/list kietrichards 3 1,699 Mar-08-2019, 07:58 PM
Last Post: Larz60+
  Can python be used to search a word document for combinations of 6 digits? gkirt1053 2 1,257 Nov-15-2018, 06:22 PM
Last Post: gkirt1053
  difference between word: and word[:] in for loop zowhair 2 1,898 Mar-03-2018, 07:24 AM
Last Post: zowhair
  Word Search Solver PythonLamer 4 3,113 Oct-12-2017, 06:13 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020