Or how to make an if-statement in a modified list.
I read StackOverflow for a while (thanks everyone). I love it. I also saw that you can ask a question and answer it yourself. Sorry if I duplicate, but I did not find this specific answer in StackOverflow.
- How do you check if an item is in the list, but change it at the same time?
My problem:
myList = ["Foo", "Bar"]
if "foo" in myList:
print "found!"
As I do not know the case of an element in the list, I want to compare it with lowercase. The obvious but ugly answer would be the following:
myList = ["Foo", "Bar"]
lowerList = []
for item in myList:
lowerList.append(item.lower())
if "foo" in lowerList:
print "found!"
Can I do it better?
source
share