'NoneType' object is not subscriptable?

user2786555 picture user2786555 · Sep 18, 2013 · Viewed 167.5k times · Source
list1 = ["name1", "info1", 10]
list2 = ["name2", "info2", 30]
list3 = ["name3", "info3", 50]
MASTERLIST = [list1, list2, list3]


def printer(lst):
    print ("Available Lists:")
    for x in range(len(lst)):
        print (lst[x])[0]

This code is returning the "'NoneType' object is not subscriptable" error when I try and run

printer(MASTERLIST)

What did I do wrong?

Answer

TerryA picture TerryA · Sep 18, 2013

The print() function returns None. You are trying to index None. You can not, because 'NoneType' object is not subscriptable.

Put the [0] inside the brackets. Now you're printing everything, and not just the first term.