Question: In this lab session, you will be using starter code which contains a function to read a file that contains names and numbers separated by
In this lab session, you will be using starter code which contains a function to read a file that contains names and numbers separated by comma a csv or comma separated file The function that reads the file and returns a list is already implemented for you. You also need to download the text file with the data to run your code make sure your py file and your txt file are in the same folder, and that you have the folder open on VS code
You are to implement three other functions:
quad that takes as argument a list of strings that could be converted to integers, floats, or are just names and returns a dictionary of only the names as keys, and counts as values
that takes as argument the dictionary you returned from the previous function, and a string representing a name. This function returns two types of message string depending on whether the name argument is a key in the counts dictionary:
The name X occurs N times.
X not found.
getmostcommonname that takes as argument the dictionary of name counts, and returns a string with a message: The name X occurs N times.
Here are some test cases:
mylist readfilenamesandnumbers.txt
mycounts countnamesmylist
print mycounts
Ian: 'Joseph': 'Hunter': 'Javier': 'Emily': 'Michael':
'Daniel': 'Cole': 'Kolbe': 'Wang': 'Kim': 'Justin':
'Paul': 'Zach': 'Renee': 'Tucker': 'Jacob': 'Alan':
Ian: 'Joseph': 'Hunter': 'Javier': 'Emily': 'Michael':
'Daniel': 'Cole': 'Kolbe': 'Wang': 'Kim': 'Justin':
'Paul': 'Zach': 'Renee': 'Tucker': 'Jacob': 'Alan':
'William': 'Gabriel': 'Singh': 'Elliott': 'Kumar':
'Richard': 'Max': 'Reddy': 'Claire': 'Jake': 'Robert':
'Rose': 'James': 'Austin': 'Aidan': 'Joshua': 'Chase':
'Noah': 'Isaac': 'Scott': 'Antonio': 'Steven': 'Emma':
'Olivia': 'Anthony': 'Adriana': 'Anna': 'Lee': 'Howard':
'Shane': 'Alexander': 'Alex': 'Megan': 'Jesus': 'Dev':
'Eduardo': 'Stephen': 'David': 'Ali': 'Tran': 'Jeremy':
'Samuel': 'Christopher': 'Noel': 'Ethan': 'Lawrence':
'Andrew': 'Grace': 'John': 'Nate': 'Taylor': 'Jose':
'Colin': 'Thomas': 'Sai': 'Logan': 'Tanner': 'Aiden':
'Lauren': 'Connor': 'Alejandro': 'Nicole': 'Ahmed': 'Elise':
'Jessica': 'Rene': 'Garcia': 'Abel': 'Hernandez': 'Martinez':
'Luke': 'Andre': 'Andres': 'Gavin': 'Mark': 'Cameron':
'Josh': 'Victor': 'Marie': 'George': 'Lucas': 'Yan':
'Dylan': 'Will': 'Brian': 'Julian': 'Drew': 'Jordan':
'Luis': 'Ashley': 'Diego': 'Tyler': 'Henry': 'Elizabeth':
'Sofia': 'Matthew': 'Williams': 'Riley': Lynn: 'Ryan':
Al: 'Allen': 'Mason': 'Carlos': 'Sebastian': 'Smith':
'Charles': 'Patrick': 'Adrian': 'Nathan': 'Brandon': 'Nick':
'Derek': 'Abdullah': 'Zachary': 'Edward': 'Jean': 'Sam':
'Angel': 'Chris': 'Michelle': 'Wayne': 'Mohammed': 'Trevor':
'Jason': 'Alec': Li: 'Martin': 'Tiffany': 'Peter':
'Jack': 'Maurice': 'Elijah': 'Ben': 'Sean': 'Anne':
'Nguyen': 'Eric': 'Adam': 'Xavier': 'Chen': 'Adnan':
'Ava': 'Caleb': 'Sophia': 'Hayden': 'Paige': 'Victoria':
'Angelina': 'Jasmine': 'White': 'Isaiah': 'Soto': 'Vivian':
'Evan': 'Jackson':
mylist readfilenamesandnumbers.txt
mycounts countnamesmylist
print lenmycounts
mylist readfilenamesandnumbers.txt
mycounts countnamesmylist
print findnamemycounts, "Adriana"
The name Adriana occurs times.
mylist readfilenamesandnumbers.txt
mycounts countnamesmylist
print findnamemycounts, "Maria"
Maria not found.
beginarrayl
text mylist readfilenamesandnumbers.txt
text mycounts countnamesmylist
text print getmostcommonnamemycounts
endarray
The name James occurs times.
def readfilefilename:
newlist
file openfilenamer
for line in file:
lineparts line.stripsplit
for p in lineparts:
newlist.appendp
return newlist
V if
name main :
mylist readfilenamesandnumbers.txt
mycounts count namesmylist
printmycounts
printlenmycounts
printfind namemycounts, "Adriana"
printfind namemycounts, "Maria"
printget mostcommonnamemycounts
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
