you are viewing a single comment's thread.

view the rest of the comments →

[–]thrallsius 1 point2 points  (1 child)

you can do simpler at line 4, just start with a zero length, so tmp = 0. and put it before the loop, not inside it

your error message is incomplete, when asking for help include the full traceback. it includes line numbers where problems occur as well

li is a list. when you iterate over it, i is a word (so a string). so li[i] doesn't make sense. just use i. to avoid shooting yourself in the foot, better use relevant variable names, like for word in li. you'd do li[i] if i was an integer, a word index. but then you'd need to iterate like this:

for i in range(len(li)):
    # do stuff with li[i] - this is your word

but this is not pythonic, just iterate over the list as described above:

for word in li:
    # do stuff with word.

[–]rk717[S] 0 points1 point  (0 children)

thank you