About 50 results
Open links in new tab
  1. python - Sort a list of lists with a custom compare function - Stack ...

    I stumbled on this thread to sort the list of lists by comparator function. For anyone who is new to python or coming from a c++ background. we want to replicate to use of the call-back function …

  2. Custom Python list sorting - Stack Overflow

    The sort () method takes optional arguments for controlling the comparisons. cmp specifies a custom comparison function of two arguments (list items) which should return a negative, zero …

  3. Sort a list with a custom order in Python - Stack Overflow

    Jan 8, 2013 · 0 Since that is not in aphabetical order I don't think there is one single function that can sort it but what you could do is create a new list and then append. This is kind of a cheap …

  4. python - Sorting based on custom sort key - Stack Overflow

    May 25, 2023 · 1 .sort and sorted functions accept a key argument, which can return a number or a tuple of numbers. Output will be sorted by first element of such tuple, then second etc. This …

  5. Custom Sorting Python Dictionary - Stack Overflow

    Aug 20, 2012 · Dictionaries are inherently unordered, so you can't directly sort the dictionary. You can sort the key/value pairs by sorting and passing in a key function just like you would when …

  6. python - Custom sorting in pandas dataframe - Stack Overflow

    Dec 12, 2012 · a b m 0 1 2 March 2 3 4 April 1 5 6 Dec The key argument takes as input a Series and returns a Series. This series is internally argsorted and the sorted indices are used to …

  7. python - How to create a custom sort for a list of strings - Stack …

    Dec 2, 2023 · To create a custom sort for a list of strings in Python, you can use the sorted () function with a custom sorting key function. Here's an example of how to do this:

  8. sorting - How to sort with lambda in Python - Stack Overflow

    Sep 22, 2010 · You're trying to use key functions with lambda functions. Python and other languages like C# or F# use lambda functions. Also, when it comes to key functions and …

  9. How to use a custom comparison function in Python 3?

    In Python 2.x, I could pass custom function to sorted and .sort functions

  10. Sorting string values according to a custom alphabet in Python

    Oct 27, 2014 · key, if spedified, should be a function that takes one argument and returns something that python knows natively how to sort. In this case, key returns a list of the indices …