Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions