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?
In python, to sort list of tuples by the first element in descending order, we have to use the sort() method with the parameter ” (reverse=True) “ which will sort the elements in descending order.
Arrays and Tuples This type is completely mutable. We can change the dimensions of it, we can push data to it. For that reason, in most cases arrays are probably the type of data you will want to work with in Julia so long as you need to change dimensions.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With