About 13,500,000 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 - 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 …

  3. Python list sort in descending order - Stack Overflow

    Apr 20, 2010 · Python list sort in descending order Asked 15 years, 1 month ago Modified 2 years, 9 months ago Viewed 918k times

  4. 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.

  5. python - How to sort pandas dataframe by one column - Stack Overflow

    If you want to sort by two columns, pass a list of column labels to sort_values with the column labels ordered according to sort priority. If you use df.sort_values(['2', '0']), the result would be sorted by …

  6. sorting - Sort a list of Class Instances Python - Stack Overflow

    Jul 27, 2012 · Sort a list of Class Instances Python [duplicate] Asked 15 years, 1 month ago Modified 13 years, 4 months ago Viewed 171k times

  7. python - How do I sort a dictionary by key? - Stack Overflow

    Jan 26, 2017 · A simple way I found to sort a dictionary is to create a new one, based on the sorted key:value items of the one you're trying to sort. If you want to sort dict = {}, retrieve all its items using …

  8. python - Explanation of Merge Sort for Dummies - Stack Overflow

    May 8, 2012 · 5 Merge sort has always been one of my favorite algorithms. You start with short sorted sequences and keep merging them, in order, into larger sorted sequences. So simple. The recursive …

  9. How do I sort a zipped list in Python? - Stack Overflow

    Apr 29, 2017 · There's good reason for both: .sort() sorts a list in-place. And sorted works on any iterator, but needs to use additional storage to accomplish the task.

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

    And the sort method has a parameter, called key, which you can pass a function. Using this parameter, your list won't be ordered by the values of the list, but by the values of your function on the list.