Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. t = int(input())  # ignore
  2. string = input()
  3.  
  4. alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  5.             'v', 'w', 'x', 'y', 'z']
  6. occurence = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  7.  
  8. #dla kazdej literki w wyrazie
  9. for char in string:
  10.     #sprawdzam ile razy występuje literka w wyrazie
  11.     for index in range(0, len(alphabet)):
  12.         #ilość wystąpien wpisuje do tablicy
  13.         occurence[index] = string.count(alphabet[index])
  14.  
  15. #dla kazdej literki alfabetu
  16. for i in range(0, len(alphabet)):
  17.     #jezeli ilość wystąpien literki jest rowna 0 to ją pomijam
  18.     if occurence[i] == 0:
  19.         continue
  20.     #jeśli jest inaczej, printuje literke wraz z jej iloscią wystapien
  21.     print(alphabet[i], occurence[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement