list1 = ["name1", "info1", 10] list2 = ["name2", "info2", 30] list3 = ["name3", "info3", 50] MASTERLIST = [list1, list2, list3] def printer(list): print ("Available Lists:") listlen = (len(list)) for x in range(listlen): print (list[x])[0]
This code returns a "NoType" error that is not indexed when I try to start printer(MASTERLIST) . What did I do wrong?
printer(MASTERLIST)
[0] must be inside ) .
[0]
)
The print() function returns None . You are trying to index None. You cannot, because the 'NoneType' object is not subscriptable .
print()
None
'NoneType' object is not subscriptable
Place [0] inside the brackets. Now you are typing everything, not just the first term.
Do not use list as a variable name so that it obscures the embedded file.
list
And there is no need to determine the length of the list. Just iterate over it.
def printer(data): for element in data: print(element[0])
Just an addition: looking at the contents of internal lists, I think they might be the wrong data structure. It looks like you want to use a dictionary.
Point A: do not use the list as a variable name Point B: you do not need only [0]
print(list[x])
Indexing, for example. [0] must be present inside the seal ...
list1 = ["name1", "info1", 10] list2 = ["name2", "info2", 30] list3 = ["name3", "info3", 50] def printer(*lists): for _list in lists: for ele in _list: print(ele, end = ", ") print() printer(list1, list2, list3)