The code I'm trying to write, is supposed to read a text file, and check how many times, 'EASTS', or 'WESTS' have scored, I can fetch the numbers by using find and 'EASTS' or 'WESTS'. But instead of getting the occurrence, I get how many times it exists in each line.
So:
1
1
1
1
(and idk why there is space before the 1's that belong to the wests')
Here is the text:
EASTS versus WESTS
EASTS have scored 25:13
WESTS have scored 26:38
WESTS have scored 40:23
WESTS have scored 42:01
And here is my code, what am I doing wrong?
name = "scores.txt"
with open(name) as f:
ff = f.readlines()[1:]
for line in ff:
words = line.split()
a = words.count('EASTS')
b = words.count('WESTS')
a_ = str(a)
b_ = str(b)
eas = a_.strip('0')
wes = b_.strip('0')
print(eas, wes)
The result should look something like this
WESTS 3
EASTS 1
Can somebody help? Thank you in advance!