Python ‘set’ object does not support indexing

appendindexingtypeerror

I am working on a Windows 7 os in a Python (3.2.2) shell. Trying to learn the language I entered and had returned the following:

>>> cast = {
    'cleese',
    'Palin',
    'Jones',
    'Idle'
    }
>>> print (cast[1])
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    print (cast[1])
TypeError: 'set' object does not support indexing
>>> cast.append('Gilliam')
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    cast.append('Gilliam')
AttributeError: 'set' object has no attribute 'append'

==========================

It seems as if the problem is not in the coding, but with how the program was installed.

I have installed, un-installed and installed again, but the resutl is the same. I there something I need to do before Python's shell is ready to be used?

hans

Best Answer

Python seems to work fine. The point is that set doesn't support indexing or appending. Try using a list instead ([] instead of {}). In place of appending, set has add, but indexing is out.

And Python has useful help,

>>> help(set)

prints a lot of info about sets.

Related Topic