Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Load the pipe-delimited file P. It is organized with 3 fields on each line: firstname|lastname|birthday. Search for the firstname F and lastname L, replacing the

Load the pipe-delimited file P. It is organized with 3 fields on each line: firstname|lastname|birthday.
Search for the firstname F and lastname L, replacing the birthday with B. Write the file back out in the same pipe-delimited format.
image text in transcribed
# Get the filepath from the command line import sys 4 P sys.argv[1] F# sys.argv[2] L- sys.argv[3] 8 sys.argvt4] 5 6 8 9 11 # 0ur Helper functions : 12 13 14 15 16 # Loads the file at filepath 17 # Returns a 2d array with the data 18 19 def load2dArrayFromFilte(filepath): # Your code goes here: with open(filepath, ) as rfile: 21 lines -rfile.read O.split('An) while in lines: 24 lines.remove( 25 LoadedArrayIline.split('1) for line in lines] rfile.close() return LoadedArray 26 27 28 29 . # Searches the 2d array ,records, for firstname, lastname . 30 # Returns the index of the record or-1 if no record exists 31 32 def findIndex (records, firstname, lastname): 33 : # Your code goes here: for line in records: if firstname return records.index (Line) line [0] and lastname # line[1]: 35. 36 37 3 return -1 8 # sets the birthday of the record at the given index 39 # Returns: nothing 40 def setBirthday (records, index, newBirthday): 41 42 43 # Your code goes here: Line records[index] Line[2] newBirthday records [index]line 45 46 # Convert the 2d array back into a string # Return the text of the 2d array 47 def makeTextFrom2dArray (records): # Your code goes here: writer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

LO2 Compare three types of individual incentives.

Answered: 1 week ago