Thrillofit86
Thrillofit86

Reputation: 619

How to get correct if-statement with similar words?

I have re-edit my question and here I am..

My problem here following:

getInfo = 'filtered'
redisURL = ['unfilteredKeywords', 'filteredKeywords', 'orangeSElinks', 'orangePLlinks']

for getRedis in redisURL:
    if getRedis in getInfo.lower():
        print(getRedis)

outprint:

unfilteredKeywords
filteredKeywords

and here is the problem. What I am trying to achieve here is that I want to be able to only print out in this case filteredKeywords and not the unfilteredKeywords.

What I expect for outprint is that it should only print out

filteredKeywords

Upvotes: 0

Views: 131

Answers (1)

glibdud
glibdud

Reputation: 7840

In this specific case, it looks like it's good enough to catch all the cases that start with getInfo:

for getRedis in redisURL:
    if getRedis.lower().startswith(getInfo.lower()):
        print(getRedis)

If this isn't representative of all cases you'll be dealing with, then basic string functions may not be sufficient for the problem. Depending on what other values getInfo may take, and what other values it would need to be distinguished from, you may eventually need to play with the re module. It's a difficult problem to generalize though.

Upvotes: 1

Related Questions