Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 10 - Lists - Programming Exercises - Page 351: 10.13

Answer

code

Work Step by Step

# 10.13 (Eliminate duplicates) 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. def eliminateDuplicates(lst): size = len(lst) i = 0 while i < size: current = lst[i] x = i + 1 while x < size: if current == lst[x]: lst.pop(x) size = len(lst) x += 1 i += 1 def main(): lst = input("Enter ten numbers: ").split() lst = [int(x) for x in lst] eliminateDuplicates(lst) print("The distinct numbers are:", lst) main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.