0

Let's say I have:

name_list = ["gxrgirl", "Octagon", "Nimble Momonga"]
feminine_words = ["girl", "princess", "wifey", "woman", "queen"]

I want to be able to detect feminine words within the name_list by using the feminine_words list.

So for example:

I would be able to detect the "girl" string within gxrgirl and have some output saying: female

I read somewhere that I can use from builtins import any , but I'm not sure how to approach it.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
The Dodo
  • 711
  • 5
  • 14

1 Answers1

0

You can use the function any() without any import statement.

It can be solved by one line:

['female' if any(word in name for word in feminine_words) else '' for name in name_list]
# It gives the following result: ['female', '', '']
Sukjun Kim
  • 187
  • 1
  • 5