forked from fenyx-it-academy/Class4-PythonModule-Week2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounting the letters
More file actions
27 lines (23 loc) · 1.26 KB
/
counting the letters
File metadata and controls
27 lines (23 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Write a code snippet that inputs a sentence from the user, then uses a dictionary to
# summarize the number of occurrences of each letter. Ignore case, ignore blanks and assume
# the user doesnot enter any punctuation. Display a two-column table of the letters and their
# counts with the letters in sorted order.
# Example:
# Input >>> "This is a sample text with several words This is more sample text with some differentwords"
# Output >>> [('a', 4), ('d', 3), ('e', 10), ('f', 2), ('h', 4), ('i', 7), ('l', 3), ('m', 4),
# ('n', 1), ('o', 4), ('p', 2), ('r', 5), ('s', 10), ('t', 9), ('v', 1), ('w', 4), ('x', 2)]
# string modulu yuklenerek kucuk harfler alinmistir.
import string
cumle=str(input("bir cumle giriniz: "))
kucuk_harfler=list(string.ascii_lowercase)
cumle=cumle.lower() # girilen string kucuk harflere donusturulmustur.
son={}
#ilk for loopu ile listedeki tum elemanlar bir defa kontrol edilerek sozluge eklenmistir.
for i in range(len(cumle)):
if cumle[i] in kucuk_harfler:
son[cumle[i]]=0
#ikinci for loopu ile bir onceki for loopu ile sozluge eklenen elemanlardan kac tane bulundugu tespit edilmektedir.
for i in range(len(cumle)):
if (cumle[i] in kucuk_harfler) and cumle[i]!=0:
son[cumle[i]] += 1
print(son)