Home>

There is a list of machines in the following form:

[{'brand_id': brand ID, 'car_name': 'car name', 'year': year, 'price': price, ...}]which is taken from the database.

How to display the next item from the list when the button is pressed further? There is an idea that you need to save somewhere the number of clicks on the "next" button and display cars [i], where i is the number of clicks on the button, but maybe you can suggest a better solution to the problem.

  • Answer # 1

    You can try creating a list iterator and then navigating to the next element using the built-in functionnext ()...

    cars_iterator= iter (cars)
    next_car= next (cars_iterator)
    

    Also, don't forget to deal with the StopIteration exception that can occur when elements end in an iterator.

  • Answer # 2

    You can try creating a list iterator and then navigating to the next element using the built-in functionnext ()...

    cars_iterator= iter (cars)
    next_car= next (cars_iterator)
    

    Also, don't forget to deal with the StopIteration exception that can occur when elements end in an iterator.