Advertisement
ganiyuisholaafeez

Removing the duplicates of elements

Mar 1st, 2020
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. """ This is a program that removes the duplicates of elements in a given list of
  2. numbers supplied by the user. Please note that the number of the elements supplied
  3. should be greater than 15, otherwise, you dont get to proceed """
  4.  
  5. type_numbers = input("Enter your list of numbers and use a comma and whitespace\
  6. as a separator between two numbers: ")
  7. list_of_numbers = type_numbers.split(", ") # The splits the numbers to a list
  8.  
  9. def remove_duplicates(numbers):
  10.     mylist = list(dict.fromkeys(numbers))
  11.    
  12.     if len(numbers) <= 15: # Checking if the numbers are upto 15
  13.         print("Error!: The number of the elements is not upto 15, it is", len(numbers))
  14.     else:
  15.         print("The length of the original list is: ", len(list_of_numbers))
  16.         print("The length of the final list is: ", len(mylist))
  17.         mylist.sort()
  18.         print("my unique and sorted list is", mylist)
  19.  
  20. remove_duplicates(list_of_numbers)
  21.  
  22.  
  23. # Enter your list of numbers and use a comma and whitespaceas a separator between two numbers: 1, 2, 3,
  24. # 4, 3, 2
  25. # Error!: The number of the elements is not upto 15,
  26. # it is 6
  27.  
  28. # Enter your list of numbers and use a comma and whitespaceas a separator between two numbers: 1, 2, 4,
  29. # 5, 5, 4, 3, 2, 4, 4, 5, 6, 3, 2, 5, 4, 3, 3, 2
  30. # The length of the original list is:  19
  31. # The length of the final list is:  6
  32. # my unique list is ['1', '2', '3', '4', '5', '6']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement