I have a single line string read from a txt file (file only has this string) in the following format:
[["abstract", "common", "reference", "introduction", "motivation"], ["real", "day", "night", "twenty", "blood", "truck", "major", "ship", "plane"], ["weapon", "guns", "nuclear", "revolver"], ["rose", "princess", "flower", "beauty", "sunflower", "soldier", "imaginary", "jasmine"], ["cloth", "shirt", "jeans", "trouser"]]
I want to retrieve all the text content between start marker = [" and end marker = "]
so my desired output should be (new line seperated):
"abstract", "common", "reference", "introduction", "motivation"
"real", "day", "night", "twenty", "blood", "truck", "major", "ship", "plane"
"weapon", "guns", "nuclear", "revolver"
"rose", "princess", "flower", "beauty", "sunflower", "soldier", "imaginary", "jasmine"
"cloth", "shirt", "jeans", "trouser"
I wrote the following code:
def fileRead(fpath):
f = open(fpath, "r")
for s in f:
start = s.find('["')
start += 1 # skip the bracket, move to the next character
end = s.find('"]', start)
print(s[start:end])
return s[start:end]
But it is giving me the following output only:
"abstract", "common", "reference", "introduction", "motivation"
Please let me know what needs to be changed to get the desired output?