Question: In PYTHON, create a text tool function uniq. The `uniq` tool detects duplicated lines in its input. It expects its input to be already sorted,

In PYTHON, create a text tool function uniq. The `uniq` tool detects duplicated lines in its input. It expects its input to be already sorted, meaning it can only detect duplicates that are adjacent in the file. This program should be run from the command line. The arguments given should be tt.py(the driver program) uniq flag(if applicable) file

For example: The original file data/dup5 is

1 1 2 2 3 4 4 5

By default it removes duplicates from its input

$ python src/tt.py uniq data/dup5 1 2 3 4 5

Given the `-c` flag `uniq` will count the number of occurrences of each line encountered:

$ python src/tt.py uniq -c data/dup5 2 1 2 2 1 3 2 4 1 5

When given the `-D` flag it prints only the duplicated lines $ python src/tt.py uniq -D data/dup5 1 1 2 2 4 4

When given the `-u` flag it only prints unique lines $ python src/tt.py uniq -u data/dup5 3 5

In the driver program I call the uniq function with the parameter(sys.argv[2:]) passed in. I have started a basic outline for the function that looks like this: DO NOT USE the set() method, or the dictionary{} data type!!!

def uniq(args): if args[0] == "-c": with open(args[1]) as f: #count the number of occurrences of each line elif args[0] == "-D": with open (args[1]) as f: #print only the duplicated lines elif args[0] == "-u": with open (args[1]) as f: #print only the unique lines else: with open(args[0]) as f: #do the default. remove duplicates 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!