0
exxy = ['mix', 'xyz', 'aardvark', 'xanadu', 'apple']

pleasework = []
ten = []

for s in exxy:
    if s[0] == 'x':
        pleasework.insert[0, s]
    else:
        ten.append[s]

pleasework.sort()
ten.sort()

pleasework.append(ten)

print pleasework

I keep getting an error that says that object is not subscriptable.

Traceback (most recent call last):
  File "/Users/jerrywalker/Desktop/CompSci/Programming/Programming_Resources/Python/idle.py", line 10, in <module>
    ten.append[s]
TypeError: 'builtin_function_or_method' object is not subscriptable

I'm not really sure what this means. I've just started Python yesterday... I'm sure it's something in the code that I'm not doing right, because even when I change the name of my variables around the error is the same.

Jerry Walker
  • 95
  • 1
  • 4
  • 11
  • Here's a link to a similar question. http://stackoverflow.com/questions/216972/in-python-what-does-it-mean-if-an-object-is-subscriptable-or-not – slider Nov 22 '13 at 04:08

2 Answers2

4

"Subscriptable" means that you're trying to access an element of the object. In the following:

ten.append[s]

you're trying to access element s of ten.append. Since you want to call it as a function/method instead, you need to use parens:

ten.append(s)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
3

You have defined two lines with the wrong syntax:

It shouldn't be:

pleasework.insert[0, s]
ten.append[s]

But rather:

pleasework.insert(0, s)
ten.append(s)

ten.append(s) is a list method and you cannot try to get a element s of ten.append(s).

Even assuming you were trying to do something like ten[s] it would still return a error because s has to be the index (which is a integer) of the element you want

K DawG
  • 13,287
  • 9
  • 35
  • 66