0

I'm unsure where I'm getting this error:

Traceback (most recent call last):
  File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 78, in <module>
    main()
  File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 74, in main
    bars(words)
  File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 62, in bars
    init(words, lst)
  File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 38, in init
    freqLegend(words,val, lst)
  File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 54, in freqLegend
    freqLegend(words, val/1.5,  counter-1)
  File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 53, in freqLegend
    back((max(lst)*1000)/10)
TypeError: 'int' object is not iterable

I think its happening in my freqLegend function where I am taking the max of lst and dividing it by 10 but I'm not iterating through anything at this point and I cant find why I am getting this error.

from letterFreq import *
from turtle import *


    def init(words, lst):

        val = max(lst)
        print(val)
        speed(0)
        setup (width=600, height=600, startx=0, starty=0)
        up()
        lt(180)
        forward(200)
        lt(90)
        forward(100)
        lt(90)
        down()
        forward(400)
        up()
        forward(-400)
        lt(90)
        down()
        forward(val*1000)
        up()
        back(val*1000+20)
        rt(90)
        forward(200)
        write("A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   "
              "R   S   T   U   V   W   X   Y   Z", True, align="center")
        goto(-200,-100)
        lt(90)
        forward((val*1000)/2)
        lt(90)
        forward(60)
        write("Frequency", True, align="center")
        rt(90)
        goto(-200,153)
        freqLegend(words,val, lst)

    def freqLegend(words, val, lst, counter = 10):

        if counter == 0:
            goto(-200,-100)
            return
        elif counter > 0:
            up()
            lt(90)
            down()
            forward(30)
            write(round(val, 3 ))
            back(30)
            rt(90)
            back((max(lst)*1000)/10)
            freqLegend(words, val/1.5,  counter-1)

    def bars(words):
        lstFreq = []
        for letters in letterFreq(words):
            lstFreq.append(letterFreq(words)[letters])

        lst = lstFreq
        init(words, lst)
        for i in lst:
            down()
            forward(i*1000)
            rt(90)
            forward(14)
            left(90)
            back(i*1000)

    def main():
        filename = "data/very_short.csv"
        words = readWordFile(filename)
        bars(words)
        input("enter to close")

    if __name__ == '__main__':
        main()

1 Answer 1

2

You're missing an argument to freqLegend, so you're getting behavior that you don't expect. You have only three arguments:

freqLegend(words, val/1.5,  counter-1)

Where I think you mean

freqLegend(words, val/1.5, lst,  counter-1)

And the reason that you are getting an error that it is not iterable is because max() actually iterates through the list. Due to the argument counter-1 being passed to the function as the argument lst, on the second call lst is an int, which it can't iterate through to find the maximum.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.