How to for loop in reverse?
algorithm, for-loop, loops, python, simulation
Solution
You can use the `reversed` built-in method to reverse the ordering of your list of lists:
for li in reversed(lvl):
print li
Output:
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
[0, 0, 1, 0, 0]
[0, 0, 1, 0, 0]
[0, 0, 1, 0, 0]
Problem
I'm making a water simulation program, and I need it to do a for loop through y, x. But I need it to check the most bottom y first, then up. This is my lvl: ``` lvl = [[0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] ``` I need it to check lvl[4] and then lvl[3], lvl[2], etc. Please help! NB: I'm using nested for loops, so I can check y, x.