Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python warning: Expected Collection.Iterable, got 'int' instead

Tags:

python

I am a Python newbie :)

Given this code:

    some_list_len = len(some_list)
    for i in some_list_len :
        print some_list[i]

Why do I get the warning in subject? How can I overcome that?

Best regards!

like image 228
dushkin Avatar asked Aug 24 '26 15:08

dushkin


1 Answers

The type of some_list_len in your code is Int, so you get the warning.

If you want to iterate some_list_len, you can implement by this:

    some_list_len = len(some_list)
    for i in range(some_list_len) :
        print some_list[i]

or directly use this:

    for element in some_list :
        ···

and if you want to use indices, you can use enumerate:

    for i, element in enumerate(some_list) :
        ···
like image 66
cloudyyyyy Avatar answered Aug 27 '26 04:08

cloudyyyyy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!