Python swears at this here.

TypeError: 'set' object does not support indexing

I can not understand where is the error.

for number in range(0,len(list)): if list[number] == summa: code 
  • And who is the list ? Python thinks it's a lot. - alexlz
  • one
    Looking at your code, I want to bring Marc Lutz's advice from his book "Learning Python":> Do not write in C collections through indexes, ignoring such a convenient tool as iterators. Unlike C, access to the elements of a collection (especially if it is some kind of custom collection) by index can be quite expensive. If indices are important when iterating, use the [ enumerate() ] [1] function. [1]: docs.python.org/2/library/functions.html#enumerate - foriton

2 answers 2

I can assume that the list in your case is set, and with it you can not do so list [number]

In any case, you are doing everything wrong.

First, don't call the list variable, so you replace the standard Python command

Second, rewrite your code like this:

 for n in my_list: if n == summa: print 'ok' 

    list you are set, and it does not have indexes - it's just a set of objects.

    Try this:

     for list_element in list: if list_element == summa: code