Skip to content

Commit

Permalink
St 12.02.2014 09:39
Browse files Browse the repository at this point in the history
	new file:   cetnost_znaku.py
  • Loading branch information
MarrekNozka committed Feb 12, 2014
1 parent 3cd2da7 commit 2d5256f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cetnost_znaku.py
@@ -0,0 +1,36 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
# Soubor: cetnost_znaku.py
# Datum: 12.02.2014 08:50
# Autor: Marek Nožka, nozka <@t> spseol <d.t> cz
# Licence: GNU/GPL
# Úloha: četnost jednotlivých znaků v textu
###########################################################################

# vytvořžím slovník, počet pro každé písmeno abecedy je 0
cetnost = {}
znaky=sorted(list('QWERTYUIOPASDFGHJKLZXCVBNM'))

for pismeno in znaky:
cetnost[pismeno] = 0

# načtu text
text=raw_input('Zadej text > ')

# počítám znaky
for pismeno in text:
pismeno = pismeno.upper()
# if ord(pismeno)>=ord("A") and ord(pismeno) <= ord('Z'):
if pismeno in znaky:
cetnost[pismeno] +=1

# vypíšu na obrazovku
for pismeno in znaky:
if cetnost[pismeno]>0 :
print pismeno,'->', cetnost[pismeno]

# vypíšu na obrazovku podruhé
for pismeno, pocet in cetnost.items():
if pocet>0 :
print pismeno,'->', pocet

0 comments on commit 2d5256f

Please sign in to comment.