1
def worker(queue):
    while True:
        if not queue.empty():
            words = 'BananA'
            words1 = 'nut'
            words2 = 'KreMA'
            words3 = 'KIVI'
            words4 = 'TesT'
            process(data, words, words1, words2, words3, words4)

def process(data, words, words1, words2, words3, words4):
    if (search != words):
        print("Words Not Found")
    if (words in search or words1 in search or words2 in search or words3 in search or words4 in search):
        print("Words Found  : " + str(Words) + "\n")
        file = open("finded.txt","a")
        file.write("Words Founds "+ str(words)
        file.close()

but, if change the line if "banana" to "Banana"

the code not work, I need Banana or BANANA or BaNaNa get equal, and get true,

1 Answers1

1

You may for example compare always lower case:

fruits = ["apple", "baNana", "cherry"]

if "banana".lower() in map(str.lower, fruits):
   print("yes")

if "BaNanA".lower() in map(str.lower, fruits):
   print("yes2")

output:

yes
yes2

EDIT:

After you edited code:

1) This code if (search != words): followed by words in search and preceded by words = 'BananA' looks like have no possibility to work - looks mutually conflicting.

2) Assuming that this yours code if (words in search or words1 in search or words2 in search or words3 in search or words4 in search): is what you want to do. Try such way:

if (words.lower() in map(str.lower, search) or words1.lower() in map(str.lower, search) or words2.lower() in map(str.lower, search) or words3.lower() in map(str.lower, search) or words4.lower() in map(str.lower, search)):

or same but written much better:

search = list(map(str.lower, search))
for w in [words, words1, words2, words3, words4]:
    if w.lower() in search:
        ...

Please note that in the second case map is enclosed by list. This is because map result is an iterator. And without this, you can use it only once.

Adam Puza
  • 1,504
  • 13
  • 9
  • oh thanks for answer, but, ı write a dictionary script, and user example input banaNa, no result, because banane is in tx files, written a BANANA, and I cannt correct all word, ı dont know which word a capitalize or non capitalize, I need, banana BananA BanaNA or BANANA or BaNANA get equal, and find all, one string. – Android Phoneix Jan 24 '19 at 13:13
  • Please give an example, because this example match all combinations that you mention. No matter what user input f.e. `BaNana` and what is in source f.e. `bANAna`. – Adam Puza Jan 24 '19 at 13:48
  • words1 = 'Banana' words2 = 'domato' words3 = 'appLe' words4 = 'chewY' words5 = 'NuT' if (words != search): print("{:<34}".format(str(word)) + " " not found in dictionary")) if (words in search or words1 in search or words2 in search or words3 in search or words4 in search): print("words found") if change the words1 BANANA not found :( – Android Phoneix Jan 24 '19 at 14:40
  • Share your exactly code, please. I do not see you using proposed changing case in above code. – Adam Puza Jan 24 '19 at 18:54
  • Adam Thanks for all, I change the code main question, because comment is small for enter full code. – Android Phoneix Jan 25 '19 at 09:08