Follow

Sooo, if you ever need a boolean output on whether a text contains at least one word of a list, you can code it in a single line in python, like this :D
```any([text.find(i)>0 for i in list])```
I feel a bit proud about figuring that out :'3 I guess a senior would do it way better tho. However, if that's the case, right now I don't feel like hearing/reading it, but as of tomorrow xD

@dev_nadine Very solid!

Possible polish:

any([i in text for i in list])

It's certainly shorter, but only clearer if the reader can handle "in" being used in two different ways.

I'd also argue that "list" is not a good variable name, because it shadows the function for turning something into a list. The Scheme convention is to use "ls". The worst choice is "l", because it looks too much like an upper-case "i", a "1", or even a vertical pipe "|". So maybe:

any([w in text for w in words])

@peterdrake OMG Thanksssss!!! 😍 😍 😍 that's waaaaayyyyy better 🖤 🖤 🖤

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.