About 53 results
Open links in new tab
  1. python - What is the difference between sorted (list) vs list.sort ...

    Use list.sort() when you want to mutate the list, sorted() when you want a new sorted object back. Use sorted() when you want to sort something that is an iterable, not a list yet. For lists, list.sort() is faster …

  2. python - Sort a list of numbers by absolute value (ignoring ...

    l.sort(key= abs, reverse = True) Lists can be sorted using the sort () method. And the sort method has a parameter, called key, which you can pass a function. Using this parameter, your list won't be …

  3. python - How to sort a list of strings? - Stack Overflow

    Aug 30, 2008 · As sort() sorts the list in place (ie, changes the list directly), it doesn't return the sorted list, and actually doesn't return anything, so your print statement prints None. If you saved your list to …

  4. algorithm - Quicksort with Python - Stack Overflow

    Quicksort is not very practical in Python since our builtin timsort algorithm is quite efficient, and we have recursion limits. We would expect to sort lists in-place with list.sort or create new sorted lists with …

  5. How to sort an integer list in Python in descending order

    Jul 31, 2023 · How to sort an integer list in Python in descending order Asked 11 years, 3 months ago Modified 2 years, 4 months ago Viewed 79k times

  6. python - Sort a part of a list in place - Stack Overflow

    Feb 16, 2010 · A good reason for in-place sort is a case where you want to sort the end of the list (that is already mostly sorted, perhaps by a less-expensive key function), and then pop the last value.

  7. python - How do I sort a list of objects based on an attribute of the ...

    Here I would use the variable name "keyfun" instead of "cmpfun" to avoid confusion. The sort () method does accept a comparison function through the cmp= argument as well.

  8. Python list sort in descending order - Stack Overflow

    Apr 20, 2010 · This is a strange answer because you do the sorting in-place but then the reversing out-of-place. If there is another variable aliasing the original list, its value afterwards will not have the …

  9. Sorting a list of lists in Python - Stack Overflow

    Aug 3, 2010 · The key argument to sort specifies a function of one argument that is used to extract a comparison key from each list element. So we can create a simple lambda that returns the last …

  10. python - Sort a list by multiple attributes? - Stack Overflow

    Nov 20, 2010 · Here's one way: You basically re-write your sort function to take a list of sort functions, each sort function compares the attributes you want to test, on each sort test, you look and see if the …