If I have a list/array of tuples like this: [(15, 36, 39), (9, 40, 41)]
How do I sort these by the first element? By the last element? By their sum?
If I have a list/array of tuples like this: [(15, 36, 39), (9, 40, 41)]
How do I sort these by the first element? By the last element? By their sum?
x=[(15, 36, 39), (9, 40, 41)]
sort(x, by=x->x[1])
sort(x, by=x->x[end])
sort(x, by=sum)
This answer your questions?
© 2022 - 2024 — McMap. All rights reserved.
first
/last
instead ofx->x[1]
/x->x[end]
, depending on what you think looks nicer – Pseudohermaphrodite