python - AttributeError: 'tuple' object has no attribute 'split' -


i'm trying write python take cipher , split letters , frequency in cipher. issue i'm having can code print frequency of letters in cipher, i'm trying them individually can turn them percentages compare them against common values found in book, example. e.g. compare count of e's in cipher average value of 12.7% in english language. issue i'm having when try , split list of letters , frequency, attributeerror: 'tuple' object has no attribute 'split'. not sure can appreciated. here code: import collections import string

def freq():     info = input("file name")     filehandle = open(info, "r")     data = filehandle.read().upper()     char_counter = collections.counter(data)     char, count in char_counter.most_common():         if char in string.ascii_uppercase:             print(char, count)             s = (char, count)             frequency = s.split(",")             freq in frequency:                 print(freq)  freq() 

this direct copy of shell

file nametest.rtf e 59 traceback (most recent call last):   file "/users/x/desktop/frequency.py", line 17, in <module>     freq()   file "/users/x/desktop/frequency.py", line 13, in freq     frequency = s.split(",")  attributeerror: 'tuple' object has no attribute 'split' 

and here doing before:

file nametest.rtf e 59 43 t 39 r 37 o 29 f 25 p 25 s 23 l 23 22 n 19 d 18 b 17 c 15 h 14 m 12 g 9  u 8 w 8 v 6 y 4 x 3 k 3 

im looking individual things of e 12% 10% etc. or similar if possible.

any appreciated. lot in advance :)

you should alter code:

def freq():     info = input("file name")     filehandle = open(info, "r")     data = filehandle.read().upper()     char_counter = collections.counter(data)     char, count in char_counter.most_common():         if char in string.ascii_uppercase:             print(char, count)             frequency = (char + str(count))             freq in frequency:                 print(freq) 

the fixed rows:

    s = (char, count)     frequency = s.split(",") 

from tiny information hard tell exact functionality of rows, solution that.


Comments