I'm creating a project in Python where I have a list of strings as follows:
lst_characters = ['Abel', 'Abigail', 'Adon', 'Akira', 'Akuma', 'Alex', 'Balrog', 'Birdie', 'Blanka', 'C. Viper']
Then, I'm checking if a given string "let's say: Akuma (foe)
" is in lst_characters
.
The way I'm doing it is:
# Sample string to check if exists in the list:
character = "Akuma (foe)"
# Lower all strings in the list:
lst_characters = [x.lower().strip() for x in lst_characters]
# Lower the sample string and check if exists in the list:
if (character.lower() in lst_characters):
print("Character (" + character + ") is in the list")
else:
print("Character (" + character + ") not found in the list")
And the result is:
Character (Akuma (foe)) not found in the list
You can run this code here - mycompiler.io.
I tried this code - "using any
" and this code - using map
and none of the code shown in the answers shows me the desired result, that is:
Show that there is an element called (
Akuma
) in thelst_characters
that matches with the sample inputAkuma (foe)
.