I am python beginner, with no previous programming knowledge. I apologize for the name of the topic, but I simply could not make a better one. Here is what I want:
letter = "w" # search for this letter in the list bellow
listL = ["z","b","y","a","c"]
for let in listL:
if let == letter:
print "found it"
break
else:
if let == listL[-1]:
print "nope can't find it"
continue
I have a list of letters, and I want to search for a particular letter in that list. If I find the letter, then everything is ok, and the for loop should stop. If I do not find it, I would like the loop to stop that current iteration, and try with the next letter in the list. If not a single letter in the list has that particular letter, then it should print "nope can't find it".
The upper code works. But I was wondering if this could be wrote a bit clearly? And by clearly I do not mean "advanced", but scholar way, an-example-from-the-book way.
Thank you.