How does python compare functions?

Function objects do not define their own comparisons or rich comparisons. Instead, they inherit from type objects which implement rich comparisons based on the object’s address in memory. So yes, it effectively uses addresses just like the built-in id() function does. In Python 3, functions are no longer orderable.

sorting a List of Map

The following code works perfectly public Comparator<Map<String, String>> mapComparator = new Comparator<Map<String, String>>() { public int compare(Map<String, String> m1, Map<String, String> m2) { return m1.get(“name”).compareTo(m2.get(“name”)); } } Collections.sort(list, mapComparator); But your maps should probably be instances of a specific class.

Find top N elements in an Array

The time could be reduced to linear time: Use the selection algorithm, which effectively find the k-th element in a un-sorted array in linear time. You can either use a variant of quick sort or more robust algorithms. Get the top k using the pivot got in step 1.

Sorting an array in C?

In C, you can use the built in qsort command: int compare( const void* a, const void* b) { int int_a = * ( (int*) a ); int int_b = * ( (int*) b ); if ( int_a == int_b ) return 0; else if ( int_a < int_b ) return -1; else return 1; … Read more