Write a python parsing script.
INPUT File
CASRegistryNumber>1314-96-1</CASRegistryNumber>
<sy>STRONTIUM MONOSULFIDE[Lewis, R.J., Sr (Ed.). Hawley's
Condensed Chemical Dictionary. 12th ed. New York, NY: Van Nostrand
Rheinhold Co., 1993, p. 1096] **PEER REVIEWED** </sy>
<sy>STRONTIUM SULPHIDE[Lewis, R.J. Sax's Dangerous Properties
of Industrial Materials. 9th ed. Volumes 1-3. New York, NY: Van
Nostrand Reinhold, 1996., p. 3024] **PEER REVIEWED**
</sy>
<sy>ANGIBID **PEER REVIEWED** </sy>
<DateRevised>Created 19830401 by DS</DateRevised>
<CASRegistryNumber>62-44-2</CASRegistryNumber>
<unii>ER0CTH01H9</unii>
<relt>3001 [ACETAMINOPHEN] (METABOLITE)</relt>
<sy>ACETAMIDE, N-(4-ETHOXYPHENYL)- **PEER REVIEWED**
</sy>
<sy>ACETIC ACID, AMIDE, N(4-ETHOXYPHENYL)-[Weast, R.C. (ed.).
Handbook of Chemistry and Physics. 60th ed. Boca Raton, Florida:
CRC Press Inc., 1979., p. C-84] **PEER REVIEWED** </sy>
<sy>PARA-ACETOPHENETIDE[IARC. Monographs on the Evaluation of
the Carcinogenic Risk of Chemicals to Humans. Geneva: World Health
Organization, International Agency for Research on Cancer,
1972-PRESENT. (Multivolume work). Available at:
http://monographs.iarc.fr/ENG/Classification/index.php, p. V13 141]
**PEER REVIEWED** </sy>
<sy>PARA-ACETOPHENETIDIDE[IARC. Monographs on the Evaluation
of the Carcinogenic Risk of Chemicals to Humans. Geneva: World
Health Organization, International Agency for Research on Cancer,
1972-PRESENT. (Multivolume work). Available at:
http://monographs.iarc.fr/ENG/Classification/index.php, p. V13 141]
**PEER REVIEWED** </sy>
<sy>ACETOPHENETIDIN **PEER REVIEWED** </sy>
CASRegistryNumber>846533-96-1</CASRegistryNumber>
<sy>Propionaldehyde, 3-(methylthio)-[Lewis, R.J. Sr. (ed)
Sax's Dangerous Properties of Industrial Materials. 11th Edition.
Wiley-Interscience, Wiley & Sons, Inc. Hoboken, NJ. 2004.,
p. 3442] **PEER REVIEWED** </sy>
<sy>Propanal, 3-(methylthio)-[Lewis, R.J. Sr. (ed) Sax's
Dangerous Properties of Industrial Materials. 11th Edition.
Wiley-Interscience, Wiley & Sons, Inc. Hoboken, NJ. 2004.,
p. 3442] **PEER REVIEWED** </sy>
<sy>Methylmercaptopropionic aldehyde[Lewis, R
The output file will look like this:
The first line of output: 1314-96-1^STRONTIUM
MONOSULFIDE^STRONTIUM SULPHIDE^ANGIBID^^
The second line of output: 62-44-2^ACETAMIDE,
N-(4-ETHOXYPHENYL)^ACETIC ACID, AMIDE,
N(4-ETHOXYPHENYL)^PARA-ACETOPHENETIDE^PARA-ACETOPHENETIDIDE^ACETOPHENETIDIN^^
The third line of the output: 846533-96-1^Propionaldehyde,
3-(methylthio)^Propanal, 3-(methylthio)^Methylmercaptopropionic
aldehyde^^
Answer:
This is done by simply opening the file in 'r' mode then using string methods to slice, replace and other methods to obtain our desired output.
CODE:
f = open("Cities.txt",'r')
file_data = f.read().splitlines()
str = ''
list1 =[]
for i in file_data:
if i.startswith('<CASReg'):
str = i.split('<CASRegistryNumber>')[1].split('</CASRegistryNumber>')[0]
str = str + '^'
elif i.startswith('<sy>'):
new_str = i.split("**")[0].split('[')[0].split('<sy>')[1]
str = str + new_str[:-1] + '^'
list1.append(str)
for i in range(0,len(list1)-1):
if len(list1[i+1])<len(list1[i]):
print(list1[i] + "^")
print(list1[-1] + "^")

OUTPUT:

THANK YOU...!!
Write a python parsing script. INPUT File CASRegistryNumber>1314-96-1</CASRegistryNumber> <sy>STRONTIUM MONOSULFIDE[Lewis, R.J., Sr (Ed.). Hawley's Condensed Chemical...