The object "NoneType" is not decryptable?

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?

+7
python nonetype
source share
6 answers

[0] must be inside ) .

+8
source share

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

Place [0] inside the brackets. Now you are typing everything, not just the first term.

+7
source share

Do not use list as a variable name so that it obscures the embedded file.

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.

+1
source share

Point A: do not use the list as a variable name Point B: you do not need only [0]

 print(list[x]) 
0
source share

Indexing, for example. [0] must be present inside the seal ...

0
source share
 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) 
0
source share

All Articles