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])
Auf dieser Seite können Sie das Online-Video Letter Frequency Construction with Text File Combining and Dictionary Value Sort mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Ralph Turchiano 01 Januar 1970 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 81 Mal angesehen und es wurde von like den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!