I am trying to create a Python definition to display a list and trying to add a feature where if the list is more than 10 it will display it horizontally.
Here's my code:
def print_vert_list(list):
index = 0
for i in list:
if len(list) > 10:
print (" ".join(list[index]) + " ".join(list[11:11+index])) + " ".join(list[21:21+index])
else:
print (" ".join(list[index]))
index += 1
And here's the log:
Traceback (most recent call last):
File "**********", line 30, in <module>
print_vert_list(file_var_list)
File "**********", line 22, in print_vert_list
print (" ".join(list[index]) + " ".join(list[11:11+index])) + " ".join(list[21:21+index])
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
You must have an element contained in the list where it is not a string. The error message is telling you that the program is breaking because you are trying to concatenate a None type with a string type. For example:
a = "string1" + "string2" print(a) # will give you string1string2But if you try
a = None + "string1" # You will get the same error messageUsing this logic, you can add a conditional check to make sure that the element of the list is not of None type, then you could successfully concatenate it