I am new to Python. I separated lists into two other lists with one having starting n elements and the other list having the ending n elements.
list = [1,2,3,4,5,6,7,8]
n=3
res = list[-n:]
list_i=[]
list_j=[]
for i in range (0,n):
list_i.append(list[i])
print(list_i)
for j in range(0,res):
list_j.append(res[j])
print(list_j)
I tried to use the same for loop for the list_j but it gives TypeError: ‘list’ object cannot be interpreted as an integer. I am not clear as the type for list and res both are <class ‘list’>
>Solution :
In your first loop, you iterate from 0 to 3.
In the second loop, you are iterating from 0 to res. res is a list with values [6, 7, 8].
The error is saying the following: A list is not an integer. Your stop value MUST be a integer.
Hope this helps!