Issue
I was trying to write a parsing routine and use the find
function. But it always gives me a -1 no matter what I search for.
doc_list = ["The Learn Python Challenge Casino.", "They bought a car", "Casinoville"]
for word in doc_list:
word.upper()
word.find("A")
Output:
'THE LEARN PYTHON CHALLENGE CASINO.'
-1
'THEY BOUGHT A CAR'
-1
'CASINOVILLE'
-1
Solution
.upper()
does not modify the string, it returns a new string.
Use it like this instead:
for word in doc_list:
print(word.upper().find('A'))
Output:
6
12
1
Answered By - Stef
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.