I have an ordered query that I want to append to a list and then split into sublists based on the price. My code is as follows:
def home(books):
grouped_books = []
for i in range(len(books) - 1):
this_book = books[i].price
next_book = books[i+1].price
if this_book != next_book and price >= 100:
r = books[:i+1]
grouped_books.append(r)
for ob in grouped_books:
books = books.exclude(id__in=[o.id for o in ob])
Upon iterating after the query is updated, this code throws an error that list index is out of range
Am I doing something wrong here? I'd appreciate your help. Thanks!