Advertisement
SimeonTs

SUPyF Lists - Extra 04. Ununion Lists

Jun 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. """
  2. Lists
  3. Check your answer: https://judge.softuni.bg/Contests/Practice/Index/425#3
  4.  
  5. 04. Ununion Lists
  6.  
  7. Problem:
  8. You will be given a sequence of integers, separated by a space. This is the primal list.
  9. Then you will receive an integer N. On the next N lines, you will receive sequences of integers.
  10. Your task is to add all elements that the primal list does not contain from the current sequence to the primal list
  11. and then remove from the primal list, all elements which are contained in the current sequence of integers.
  12. If there are several occurrences, remove all occurrences you find.
  13. After you are done receiving lists and manipulating the primal list, sort the primal list and print it.
  14.  
  15. """
  16.  
  17. nums = [int(item) for item in input().split(" ")]
  18. count_times = int(input())
  19.  
  20. while True:
  21.     if count_times == 0:
  22.         break
  23.     current_sequence = [int(item) for item in input().split(" ")]
  24.     for current_num in current_sequence:
  25.         if current_num not in nums:
  26.             nums += [current_num]
  27.         elif current_num in nums:
  28.             while current_num in nums:
  29.                 nums.remove(current_num)
  30.     count_times -= 1
  31.  
  32. nums.sort()
  33. for num in nums:
  34.     print(num, end=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement