python question. Question 1 require to download the "NovelEnglish_All.txt" file # All Necessary Modules Have Been Imported # Do Not Import Any Additional Modules import json, datetime, csv from pprint import pprint def txt_to_csv(input_file): """ Question 1 - NovelEnglish_All.txt contains information about English novels. - Read the NovelEnglish_All.txt with FILE I/O or CSV. - Use a list of lists to make a CSV file with the appropriate data WITHOUT WHITESPACE (remove \n) named "novels.csv". - Ensure you using the correct delimiter for each line ("\t") - Exclude the "Corpus" column, and strip the quotes from the "Author" column. - Return the list of lists. Args: input_file (NovelEnglish_All.txt) Returns: List of lists Output: [['id', 'Year', 'Author', 'Title'], ['1', '2001', 'Martel,Yann', 'LifeofPi'], ['2', '2002', 'Kidd,SueMonk', 'TheSecretLifeofBees'], ['3', '2002', 'Sebold,Alice', 'LovelyBones'], ['4', '2003', 'Hosseini,Khaled', 'TheKiteRunner'], ... ['1210', '2015', 'William,EliKP', 'CashCrashJubilee'], ['1211', '2015', 'Womack,Gwendolyn', 'TheMemoryPainter']] pprint(txt_to_csv("NovelEnglish_All.txt"))
python question. Question 1 require to download the "NovelEnglish_All.txt" file
# All Necessary Modules Have Been Imported
# Do Not Import Any Additional Modules
import json, datetime, csv
from pprint import pprint
def txt_to_csv(input_file):
"""
Question 1
- NovelEnglish_All.txt contains information about English novels.
- Read the NovelEnglish_All.txt with FILE I/O or CSV.
- Use a list of lists to make a CSV file with the appropriate data WITHOUT WHITESPACE (remove \n) named "novels.csv".
- Ensure you using the correct delimiter for each line ("\t")
- Exclude the "Corpus" column, and strip the quotes from the "Author" column.
- Return the list of lists.
Args:
input_file (NovelEnglish_All.txt)
Returns:
List of lists
Output:
[['id', 'Year', 'Author', 'Title'],
['1', '2001', 'Martel,Yann', 'LifeofPi'],
['2', '2002', 'Kidd,SueMonk', 'TheSecretLifeofBees'],
['3', '2002', 'Sebold,Alice', 'LovelyBones'],
['4', '2003', 'Hosseini,Khaled', 'TheKiteRunner'],
...
['1210', '2015', 'William,EliKP', 'CashCrashJubilee'],
['1211', '2015', 'Womack,Gwendolyn', 'TheMemoryPainter']]
pprint(txt_to_csv("NovelEnglish_All.txt"))
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images