Jun 21, 2024 at 9:15pm UTC
Hello everyone,
I do not know, if it is possible to find the minimum first element in a tuple without using sort function. I have a tuple like this : data=[ ( 23, a, 3.78, d), ( 11, x, 5.8, w)] . I need to obtain the second element which is (11, x, 5.8, w) since 11<23. Is there any way to do it without using sort function ?
Thank you so much in advance.
Jun 22, 2024 at 12:50am UTC
of course it is. you can iterate all your tuples and keep track of the smallest one via your condition. You don't WANT to sort data to find the lowest element:
iterating each element once and finding the smallest takes N operations.
Sorting, usually, takes at least N(lg(N)) operations, which is only a little more than N for a few items but quite a lot more when you start having many items.
if you only have 2 items, its just a flat compare.
Last edited on Jun 22, 2024 at 12:51am UTC
Jun 23, 2024 at 8:38am UTC
Thank you so much @jonnin and @George P