SimeonTs

SUPyF2 Dictionaries-Lab - 04. Odd Occurrences

Oct 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. """
  2. Dictionaries - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1736#3
  4.  
  5. SUPyF2 Dictionaries-Lab - 04. Odd Occurrences
  6.  
  7. Problem:
  8. Write a program that extracts all elements from a given sequence of words that are present
  9. in it an odd number of times (case-insensitive).
  10. • Words are given on a single line, space separated.
  11. • Print the result elements in lowercase, in their order of appearance.
  12.  
  13. Examples:
  14. Input                                   Output
  15. Java C# PHP PHP JAVA C java             java c# c
  16. 3 5 5 hi pi HO Hi 5 ho 3 hi pi          5 hi
  17. a a A SQL xx a xx a A a XX c            a sql xx c
  18. """
  19. # My way of doing things complicated :D :
  20. # words = [word.lower() for word in input().split()]
  21. # print(*{word: words.count(word) for word in words if words.count(word) % 2 != 0}.keys())
  22.  
  23. words = input().split()
  24.  
  25. dictionary = {}
  26.  
  27. for word in words:
  28.     lower_word = word.lower()
  29.     if lower_word not in dictionary:
  30.         dictionary[lower_word] = 0
  31.     else:
  32.         dictionary[lower_word] += 1
  33.  
  34. for key, value in dictionary.items():
  35.     if value % 2 == 0:
  36.         print(key, end=" ")
Add Comment
Please, Sign In to add comment