Listing of objects
-
How do you frustrate a list of objects the python? Let's say a list like this:
array = [ {'x': 9, 'y': 357}, {'x': 19, 'y': 357}, {'x': 20, 'y': 357}, {'x': 21, 'y': 357} ]
We need to quarry (upgrading) on the key of the object.
x
-
If you need to change the reference list, use the function.
sort
:array.sort(key=lambda dict_:dict_["x"])
and if a new one is to be created,
sorted
array2 = sorted(array, key=lambda dict_:dict_["x"])