Suubi7

Recursion Solution

Oct 26th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. num = [1, 5, 7, 12, 5, 7, 2, 0]
  2.  
  3. def find_duplicates(input_list):
  4. seen = set()
  5. duplicates = []
  6.  
  7. for num in input_list:
  8. if num in seen:
  9. duplicates.append(num)
  10. else:
  11. seen.add(num)
  12.  
  13. return duplicates
  14.  
  15. duplicates = find_duplicates(num)
  16.  
  17. if duplicates:
  18. print("The repeated numbers are:", duplicates)
  19. else:
  20. print("No repeated numbers found.")
  21.  
Add Comment
Please, Sign In to add comment