pop takes an index that is removed from the list and the value that was on this index is returned.
You are not giving it an index - but a max value - indexes into lists must be integers of course.
You could work somthing out with .find() - or overthink your whole approach:
Sometimes it is easier to do things with some knowledge about python libraries.
Especially: collections.Counter
It is a specialized dictionary that is good in counting, it will pass your whole text once and add/increment its keys for each character. You are invoking .count() 26 times - once for each character inside string.ascii_lowercase - each time traversing the whole string to count the occurence of once character in it.
from collections import Counter
import string
t = """This is not a hamlet text, just a few letters and words.
Including newlines to demonstrate how to optimize your approach.
Of counting character frequencies..."""
# if you want all characters starting with a zero count, you can add and remove them
# if you do not need all characters, skip this step and go to c.update()
c = Counter(string.ascii_lowercase) # all have count of 1
c.subtract(string.ascii_lowercase) # now all are present with count of 0
# count all characters, passes text once
c.update(t.lower()) # you can input your file.read() here, any iterable will do
# sum all character counts
totalSum = sum(c.values())
# get the countings ordered max to min as tuples (Char,Count), modify
# with list comprehension to your float values. They are still ordered
top_n = [ (a,b/totalSum) for a,b in c.most_common()]
# use this to strip f.e. .,! and \n from the output:
# top_n = [ (a,b/totalSum) for a,b in c.most_common() if a in string.ascii_lowercase]
import pprint
pprint.pprint(c)
pprint.pprint(top_n)
Output:
Counter({' ': 22, 't': 15, 'e': 14, 'o': 11,
'n': 10, 'a': 9, 'i': 9, 'r': 8,
's': 8, 'c': 6, 'h': 5, 'u': 5,
'.': 5, 'd': 4, 'l': 4, 'w': 4,
'f': 3, 'm': 3, 'p': 3, 'g': 2,
'\n': 2, 'j': 1, 'q': 1, 'x': 1,
'y': 1, 'z': 1, ',': 1, 'b': 0,
'k': 0, 'v': 0})
[(' ', 0.13924050632911392), ('t', 0.0949367088607595),
('e', 0.08860759493670886), ('o', 0.06962025316455696),
('n', 0.06329113924050633), ('a', 0.056962025316455694),
('i', 0.056962025316455694), ('r', 0.05063291139240506),
('s', 0.05063291139240506), ('c', 0.0379746835443038),
('h', 0.03164556962025317), ('u', 0.03164556962025317),
('.', 0.03164556962025317), ('d', 0.02531645569620253),
('l', 0.02531645569620253), ('w', 0.02531645569620253),
('f', 0.0189873417721519), ('m', 0.0189873417721519),
('p', 0.0189873417721519), ('g', 0.012658227848101266),
('\n', 0.012658227848101266), ('j', 0.006329113924050633),
('q', 0.006329113924050633), ('x', 0.006329113924050633),
('y', 0.006329113924050633), ('z', 0.006329113924050633),
(',', 0.006329113924050633),
('b', 0.0), ('k', 0.0), ('v', 0.0)]
letter_frequency.pop(a_float)to do? You might've wanted.removeinstead. - internet_user_) is traditionally used for values you want to throw away. It makes your code much harder to read when used like this. - roganjoshmaxfunction. it's withpopfunction. I recommend you see pop function doc. - ᴀʀᴍᴀɴ