I have a text file, and I want to extract certain words. I would want to extract:
Astrid et al. 1980
Bertrand & Calbert 1985
Dilbert et al. 1990
Egbert, Fluff & Gilbert 2000
Here is a snippet of my code:
f=open("filename.txt", "r")
words = []
intergers =[]
for line in f:
# # print lines
print(line)
# splitted words
words.append(line.split())
# print(words)
intergers = line.split('(', 1)[1].split(')')[0]
The text file contains the following:
In the beginning Astrid et al. (1980) claimed that the world was flat.
Bertrand & Calbert (1985) regarded the world as pear-shaped (though it
wasn’t really) and it was also claimed that the world was oval (Dilbert
et al. 1990). It is now known, however, that the world is square,
following the work of Egbert, Fluff & Gilbert (2000).
CodePudding user response:
I would suggest you look into regular expressions, which you can read about
You can check the repl here: https://replit.com/@veedata/AssuredViolentSynergy