Frogramming (Novice) tice Problems Help Session 2 write a function to read the l
ID: 3573642 • Letter: F
Question
Frogramming (Novice) tice Problems Help Session 2 write a function to read the list of keyvalue pairs from a file. Each line of the file contains a single key value p separated by a vertical bar (D character. The function will be given the filename and will return a list of lists. Each element of the list is a list with two name (string) and court (nt. You must parse each line and convert the value to an integer and if the value is invalid do not addit to the list. You must handle uuuu au and ret oints out of Use the following function definition def myBuild(filename): Answer: 1- def my Build(filename): try: f open filename r') except: return 0 results 7. for line in f readlinesO v line. split("I") try i int(v[1]) except continue item [v[0] ,ij results append( item) return results Detailed test results unavailable. Probably an empty answer, or the question is not set to use the required Adaptive Behaviour. Debug: source code from all test runsExplanation / Answer
def myBuild(filename):
lol = []
try:
f = open(filename,'r')
except:
return []
for line in f:
l = line.strip()
l = l.split("@")
lol.append(l)
return lol
print(myBuild("tempist.txt"))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.