Search code examples
pythonlistappendsublist

How to put items inside of a sublist?


I have this python code for a project to my Intelligent Systems degree:

l = [("ola",[[1,2,3],[3,5,6]])]
l[0][1].append[6,7,8]
print(l)

When I tried it it keeps giving me this error:

TypeError: 'builtin_function_or_method' object is not subscriptable

It does not work. I want to append [6,7,8] next to [1,2,3],[3,5,6], so as an output I would want:

[("ola",[[1,2,3],[3,5,6],[6,7,8]])]

Solution

  • This will work:

    l[0][1].append([6,7,8])
    

    You just forgot the parentheses when calling append. The error is telling you that you cannot index ("subscript") the function append.