I'm currently building an image pixel iterator, and I'm picking a point on the 2D grid and iterating outwards (up, down, left, right, etc...). As I was developing, I wrote a for-loop like this to see how it would function:
expanding = [1, 2]
# Expected functionality: continues to iterate "3" forever.
for expand in expanding:
expanding.append(3)
I would expect this to continue in an infinite loop, with the iterating sequence looking like: 1
, 2
, 3
, 3
, 3
, 3
,...
so forth. Though it only seems to close on 2
due to the structure of my outputs.
This part of my algorithm is tasked with breaking an image into its colour groups by picking random coordinates and expanding outwards, checking if the colour range is too far out of the parent colour, hence the requirement of a continuous iterator till it finalizes at nothing.
The use would be being able to simply append to the array for it to be iterated in the future, without needing to finish the array and remove specific elements before continuing, as a "live for loop".