1. Make a function called fileSort(). fileSort() should take in three parameters which will correspond to arguments in the following order from left to right: a. The name of a .csv file to open and read in the contents. b. The name of a .csv file to open and write out to. c. A flag which specifies what your function should do with the contents of the .csv file.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

python please help no other answers have been right :(

 
1. Make a function called fileSort(). fileSort() should take in three parameters which will
correspond to arguments in the following order from left to right:
a. The name of a .csv file to open and read in the contents.
b. The name of a .csv file to open and write out to.
c. A flag which specifies what your function should do with the contents of the .csv
file.
2. Assume that the contents of the .csv file you are reading from contains records which all
contain 3 elements e.g. the .csv has 3 columns. Also assume there is NO HEADER on the
input file. You should start by reading the contents of the .csv file into a list of lists. Your
job then is to write a custom sorting algorithm that will sort ALL the records based on
the value at one position in each record based on the flag (third parameter).
a. If the third parameter is equal to 0 then you should sort the list of lists based on
the value of at the 0th index of each record (list element). Assume it is an int.
b.
If the third parameter is equal to 1 then you should sort the list of lists based on
the value of at the 1st index of each record (list element). Assume it is an int.
c. If the third parameter is equal to 2 then you should sort the list of lists based on
the value of at the 2nd index of each record (list element). Assume it is an int.
3. For example: Lets say your csv file contained the following records: [cats, dogs, turtles],
[turtles, cats, dogs], [dogs,turtles, cats]. If your third parameter was 2 then you should
produce the following sorted list of lists: [dogs,turtles,cats], [turtles, cats, dogs],
[cats, dogs,turtles]. Note that the contents of the lists (records) are not changing in
terms of the ordering of the elements, rather the lists themselves are being rearranged
in the larger list.
4. Now: Write out your newly sorted list of lists to the file specified in your second
parameter. Write in "write" mode not "append" mode. Your function does not need to
return anything.
Transcribed Image Text:1. Make a function called fileSort(). fileSort() should take in three parameters which will correspond to arguments in the following order from left to right: a. The name of a .csv file to open and read in the contents. b. The name of a .csv file to open and write out to. c. A flag which specifies what your function should do with the contents of the .csv file. 2. Assume that the contents of the .csv file you are reading from contains records which all contain 3 elements e.g. the .csv has 3 columns. Also assume there is NO HEADER on the input file. You should start by reading the contents of the .csv file into a list of lists. Your job then is to write a custom sorting algorithm that will sort ALL the records based on the value at one position in each record based on the flag (third parameter). a. If the third parameter is equal to 0 then you should sort the list of lists based on the value of at the 0th index of each record (list element). Assume it is an int. b. If the third parameter is equal to 1 then you should sort the list of lists based on the value of at the 1st index of each record (list element). Assume it is an int. c. If the third parameter is equal to 2 then you should sort the list of lists based on the value of at the 2nd index of each record (list element). Assume it is an int. 3. For example: Lets say your csv file contained the following records: [cats, dogs, turtles], [turtles, cats, dogs], [dogs,turtles, cats]. If your third parameter was 2 then you should produce the following sorted list of lists: [dogs,turtles,cats], [turtles, cats, dogs], [cats, dogs,turtles]. Note that the contents of the lists (records) are not changing in terms of the ordering of the elements, rather the lists themselves are being rearranged in the larger list. 4. Now: Write out your newly sorted list of lists to the file specified in your second parameter. Write in "write" mode not "append" mode. Your function does not need to return anything.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education