I will use the syntax and Python objects to represent the problem, but it is actually intended for a model in SQL databases, with the Python API and ORM.
I have a list of numbers like this:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
From time to time, some numbers are deleted, and voids remain:
[0, 1, 2, None, None, 5, 6, None, None, None, 10]
What I need to do is effectively pack this set of numbers at the maintenance stage, performed periodically, in both ordered and disordered ways, so there should not be spaces between numbers:
So, in an orderly manner, I need this list:
[0, 1, 2, 5, 6, 10, None, None, None, None, None]
And when disordered, it really doesn't matter where each number goes, unless there are zero spaces between them.
, , , , .
, , . , 5, 6 2 , 10 5 .
[0, 1, 2, None, None, 5, 6, None, None, None, 10]
[0, 1, 2, 5, 6, None, None, None, None, None, 10]
[0, 1, 2, 5, 6, 10, None, None, None, None, None]
, , , , . , , 0, 1, 2 6 10:
[None, None, None, None, None, 5, 6, 0, 1, 2, 10]
, . , , .
, , , . ?