Advertisement
SimeonTs

SUPyF Dictionaries - 01. Odd Occurrences

Jun 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. """
  2. Dictionaries and Functional Programming
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/945#0
  4.  
  5. SUPyF Dictionaries - 01. Odd Occurrences
  6.  
  7. Problem:
  8. Write a program that extracts from a given sequence of words all elements that present in it odd number of times
  9. (case-insensitive).
  10. - Words are given in 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. words = [word for word in input().lower().split(" ")]
  20.  
  21. print_words = []
  22. odd_occurrences = {}
  23.  
  24. for word in words:
  25.     odd_occurrences[word] = words.count(word)
  26.  
  27. for item, value in odd_occurrences.items():
  28.     if value % 2 != 0:
  29.         print_words += [item]
  30.  
  31. print(", ".join(print_words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement