Write a function that returns a new list by eliminating the duplicate values in the list. Use the following function header: def eliminateDuplicates(lst): Write a test program that reads in a list of integers, invokes the function, and displays the result. Here is the sample run of the program

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
icon
Related questions
Question

Q1:Write a function that returns a new list by eliminating the
duplicate values in the list. Use the following function header:
def eliminateDuplicates(lst):
Write a test program that reads in a list of integers, invokes the function,
and displays the result. Here is the sample run of the program


Enter ten numbers: 2 3 2 1 6 3 4 5 2
The distinct numbers are: 1 2 3 6 4 5

Q2:Write a program that reads in your Q1 Python
source code file and counts the occurrence of each keyword in the file.
Your program should prompt the user to enter the Python source code filename.

This is the Q1: code:

def eliminateDuplictes(lst):
newlist = []
search = set()
for i in lst:
if i not in search:
newlist.append(i)
search.add(i)
return newlist


a=[]
n= int(input("Enter the Size of the list:"))
for x in range(n):
item=input("\nEnter element " + str(x+1) + ":")
a.append(item)

result = eliminateDuplictes(a)

print('\nThe distinct numbers are: ',"%s" % (' '.join(result)))

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Linked List Representation
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr