Letter Frequency Construction with Text File Combining and Dictionary Value Sort

Pubblicato il: 01 gennaio 1970
sul canale di: Ralph Turchiano
81
like

This is dirty code, but it should be easy to understand. First we combine text files and the calculate letter frequency in order to compare science article to tabloid articles. Code Posted Below:
#pythoncode #cryptography #letterfrequency
filenames = ['crypt1.txt', 'crypt2.txt', 'crypt3.txt','crypt4.txt','crypt5.txt']
with open('cryptall.txt', 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
outfile.write(infile.read())
ggg = 'cryptall.txt'
ggh = open(ggg)
ggj =ggh.read().split()
print(ggj)
fname = "cryptall.txt"
fh = open(fname)
freq = dict()
tota = 0
lk1 = fh.read().split()
print("SCIENCE ARTICLES", "Cryptography Test")
for x in lk1:
for z in x:
for fg in z:
tota +=1
freq[fg]=freq.get(fg,0) +1
for hjk,gl in freq.items():
hj = round((gl/tota) *100,2)
freq[hjk]=hj,gl
lc = sorted([(k,v) for v,k in freq.items()], reverse = True)
for rdout in lc[:6]:
print(rdout[0][0],"% " ,"Letter", rdout[1])


In questa pagina del sito puoi guardare il video online Letter Frequency Construction with Text File Combining and Dictionary Value Sort della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Ralph Turchiano 01 gennaio 1970, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 81 volte e gli è piaciuto like spettatori. Buona visione!