In this lab, you will be tasked with writing several functions that do various tasks with sets, dictionaries and file I/O.
You should create one file named lab9.py
and put all of the functions you complete, along with the test-cases, in the same file.
Submit just this file to D2L when you are finished.
Write a function named union .
This function will take two parameters, each will be a set with arbitrary elements.
This function will return a new set that is the union of the two.
The "union" of two sets is all of the elements from both of the parameter sets.
For example, running these tests:
|
Write a function named intersection .
This function will take two parameters, each will be a set with arbitrary elements.
This function will return a new set that is the intersection of the two.
The "union" of two sets is all of the elements that appear in both of the sets being intersected.
For example, running these tests:
|
Write a function named one_appearance_names .
This function will take a single argument.
The argument will be astring of space-separated names (or really, just words in general).
This function will determine which of the names appear exactly one, and print them out.
This function is not allowed to use lists (other than for splitting the input string), dictionaries, or the count function.
In other words, you should use only sets and set operations.
For example, if this test case is executed:
|
Write a function named average_grade .
This function will accept two parameters.
The first will be the name of a csv file, which will contain student grades for a class.
The second will be a column number to average.
This function will computer the average of all the grades in a particular column in the CSV file (not including the first row of labels).
The column name along with the computed average will be printed.
For example, create a file named grades.csv in the same directory as your program with these contents.
|
Write a function named group_words .
This function will accept two parameters, the name of an input file and the name of an output file.
Ths input file should be a simple text file with one word on each line.
The output file is the file we will open and write the results into.
The function should open the input file, read in the contents, and then group all of the words based on the letter they begin with.
You should also normalize all of the words into lower-case.
For example, create a file named fruits.txt in the same directory as your program with these contents.
|
You must turn in at least 4 of the problems on D2L to get credit for this.