-2

I am making a program with lists and selection but I cannot get the programme to output only the sections of the list i want. the error is somewhere in here:

print(randomlist[0,3,6,9,12,15,18])
print(randomlist[1,4,7,10,13,16,19])
print(randomlist[2,5,8,11,14,17,20])

Before it is asked: The list works, it is with the right name, and there are 21 items in the list. Error says 'NoneType' object is not subscriptable' and I don't really know what it means

1 Answers1

0

You cannot access multiple elements from a list by indexing a comma separated string. However, you should familiarize yourself with slice notation.

Since you know the indexes of the elements you are trying to access, I think you're looking for this:

print([randomlist[i] for i in (0,3,6,9,12,15,18)])
ILostMySpoon
  • 2,399
  • 2
  • 19
  • 25