About 12,300,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 · 8 But how does this handle language specific sorting rules? Does it take locale into account? No, list.sort() is a generic sorting function. If you want to sort according to the Unicode …

  3. 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 …

  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. 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 - Explanation of Merge Sort for Dummies - Stack Overflow

    May 8, 2012 · The merge_sort function is simply a function that divides a list in half, sorts those two lists, and then merges those two lists together in the manner described above. The only catch is that …

  8. 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 …

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

    Apr 29, 2017 · The first two answers show off a pet peeve of mine about Python: the presence of both sorted and sort.

  10. Python data structure sort list alphabetically - Stack Overflow

    I am a bit confused regarding data structure in python; (),[], and {}. I am trying to sort a simple list, probably since I cannot identify the type of data I am failing to sort it. My list is simp...