I was wondering how to ignore or avoid the next same word as the first in some text using document?
I was searching for it but did not find any that close enough to what I'm imagining.
Let say I have these line in a text file
Group: 12 Cat: 100 Hen: 12 Cat: 200 Time: 328392 Cat: 123
I want the value for the first Cat
only that is 100.
I know I can use split
and if-else
statement to find what I want like
if "Cat: 100" in line:
value = line.split("Cat: ")[1].split("Hen: ")[0]
which will give me the result 100
But what if I do not know the condition for it? For example I do not know the value of the first Cat
whether it is 100 or 1242 or else?
Does anyone have any suggestion or solution for it? Thank you for your help.