Question: This code works perfect for one single paragraph. But what if we have 1000 paragraphs in one txt file. The code does not work:
This code works perfect for one single paragraph. But what if we have 1000 paragraphs in one txt file. The code does not work:
import csv data = "1. KOSTIOUK, Evgueni, Alzey, Germany; Poland; DOB 13 Jun 1954; nationality Belarus; Gender Male (individual) [RUSSIA-EO14024]. Designated pursuant to sections 1(a)(i) of Executive Order 14024 of April 15, 2021, 'Blocking Property With Respect To Specified Harmful Foreign Activities of the Government of the Russian Federation,' 86 FR 20249, 3 CFR, 2021 Comp., p. 542 (Apr. 15, 2021) (E.O. 14024) for operating or having operated in the technology sector of the Russian Federation economy. 2. GAZPROM VNIIGAZ, OOO (Cyrillic: ООО ГАЗПРОМ ВНИИГАЗ) (a.k.a. GAZPROM VNIIGAZ; a.k.a. LLC VNIIGAZ; a.k.a. OBSHCHESTVO S OGRANICHENNOI OTVETSTVENNOSTYU 'NAUCHNO-ISSLEDOVATELSKI INSTITUT PRIRODNYKH GAZOV I GAZOVYKH TEKHNOLOGI - GAZPROM VNIIGAZ' (Cyrillic: НАУЧНО-ИССЛЕДОВАТЕЛЬСКИЙ ИНСТИТУТ ПРИРОДНЫХ ГАЗОВ И ГАЗОВЫХ ТЕХНОЛОГИЙ - ГАЗПРОМ ВНИИГАЗ); f.k.a. "ALL UNION SCIENTIFIC RESEARCH INSTITUTE OF NATURAL GASES AND GAS TECHNOLOGIES"; a.k.a. "LIMITED LIABILITY COMPANY SCIENTIFIC RESEARCH INSTITUTE OF NATURAL GASES AND GAS TECHNOLOGIES"; a.k.a. "VNIGAZ") Gazovikov St., bld. 1, Razvilka, Leninski Raion, Moskovskaya obl. 142717, Russia; Sevastopolskaya St. 1A, Ukhta, Komi Republic, Russia; Website www.vniigaz.ru; Email Address a..m@vniigaz.gazprom.ru; Executive Order 13662 Directive Determination - Subject to Directive 4; Secondary sanctions risk: Ukraine-/Russia-Related Sanctions Regulations, 31 CFR 589.201 and/or 589.209; Organization Established Date 30 Jun 1999; Registration ID 1025000651598; Tax ID No. 5003028155. 3. NAUCHNO-PROIZVODSTVENNOE PREDPRIYATIE GURAMI ELEKTRONIKS (a.k.a. NPP GURAMI ELEKTRONIKS), ul. Profsoyuznaya d. 37A, floor/office 4/412, Naro-Fominsk 143306, Russia; Tax ID No. 5030098049 (Russia); Registration Number 1205000027770 (Russia) [RUSSIA-EO14024]. Designated pursuant to section 1(a)(i) of Executive Order 14024 for operating or having operated in the electronics sector of the Russian Federation economy. 4. PROISTOK OOO (a.k.a. PROISTOCK), ul. Aerodromnaya d. 8, lit. A, pomeshch. 235, Saint Petersburg 197348, Russia; Tax ID No. 7814646621 (Russia); Registration Number 1167847164605 (Russia) [RUSSIA-EO14024]. Designated pursuant to section 1(a)(i) of Executive Order 14024 for operating or having operated in the electronics sector of the Russian Federation economy." id_name = data.split(",")[0] id_parts = id_name.split(". ") id = id_parts[0] name = id_parts[1] description = ",".join(data.split(",")[1:]).strip() output = [[id, name, description]] with open('output.csv', mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(['ID', 'NAME', 'DESCRIPTION']) writer.writerows(output) print(f"ID={id}, NAME={name}, DESCRIPTION={description}")
Step by Step Solution
There are 3 Steps involved in it
To process multiple paragraphs you need to iterate over each paragraph and perform the same operations Heres how you can modify your code to handle mu... View full answer
Get step-by-step solutions from verified subject matter experts
