Homework 10: De-Dup Program
Objective: To write a program to remove duplicates from a list
Write a program that inputs a list of integers from the user, and removes the duplicate list elements, plus outputs their min and max values. Here is some sample output:
[cpersiko@fog cs110a]$ python3 dedup.py.txt
Please enter some positive integers, hitting return after each one. Enter 'q' to quit:
2
3
2
2
2
2
q
You entered 2 unique numbers:
2 3
with minimum value: 2 and maximum value: 3
[cpersiko@fog cs110a]$ python3 dedup.py.txt
Please enter some positive integers, hitting return after each one. Enter 'q' to quit:
10
5
9
1
5
10
q
You entered 4 unique numbers:
10 5 9 1
with minimum value: 1 and maximum value: 10
[cpersiko@fog cs110a]$ python3 dedup.py.txt
Please enter some positive integers, hitting return after each one. Enter 'q' to quit:
2.5
You entered 0 unique numbers:
[cpersiko@fog cs110a]$ python3 dedup.py.txt
Please enter some positive integers, hitting return after each one. Enter 'q' to quit:
4
5
-3
You entered 2 unique numbers:
4 5
with minimum value: 4 and maximum value: 5
[cpersiko@fog cs110a]$ python3 dedup.py.txt
Please enter some positive integers, hitting return after each one. Enter 'q' to quit:
55
22
22
75
42
68
q
You entered 5 unique numbers:
55 22 75 42 68
with minimum value: 22 and maximum value: 75
[cpersiko@fog cs110a]$
Hints and Rules
- Your program should stop the input if anything other than a positive integer is entered. You may want to use the "isdecimal()" function and/or others described in
the Python docs for string methods.
- Your program should have at least 2 functions, including a main() function (no global variables or global code other than a call to main within an if-statement)
- If at least one positive integer is entered, your program should output the smallest (minimum) and largest (maximum) values in the list.
- When the program is finished, the program must have a list that stores each number only once (without duplicates), in the same order they were entered.
So you can't just skip outputting the duplicates - you have to remove them (or replace them)
- The easiest and most efficient way to do this is to store only the non-repeating elements (only store a number in the array the first time you see it). You can use the "in" or "not in" boolean operators described in
section 10.5 of your book.
- A more intuitive and more complicated way to do it is to input all the numbers from the user into a list, and then change the list so it contains only the distinct numbers entered by the user. To remove the duplicates, you should make it appear as if the elements hadn't been there. So do not just set duplicates to an "empty" value, but delete them (you can use the del statement described in
section 10.9 of your book)
- Every function (except main) needs to have a comment in a triple-quoted string at the beginning, briefly explaining what it does.
- As with every assignment, you must write all the code yourself. Do not copy any code other people have written. If you use any Python features we haven't covered in class then the graders will search the internet for that code, to make sure you didn't copy it from a web site.
- Make sure to put a comment at the top of your program with your name, the name of this assignment and class (110A Homework 10), and a brief description of what the program does.
- Make sure to submit your homework using Canvas.