About 20,100,000 results
Open links in new tab
  1. 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.

  2. python - Why does "return list.sort ()" return None, not the list ...

    Python built-ins stick to one or the other; methods on immutable types like str do chain (they can't mutate in place, so they return a new object with the mutation applied), while most methods on …

  3. python - How do I sort a list of datetime or date objects ... - Stack ...

    Jan 23, 2013 · If your list is a mixture of date and datetimes, you can normalize them all into datetime objects, and then sort; again, as a key so that the type of the items in the original list doesn't change.

  4. python - pandas groupby, then sort within groups - Stack Overflow

    I want to group my dataframe by two columns and then sort the aggregated results within those groups. In [167]: df Out[167]: count job source 0 2 sales A 1 4 sales B...

  5. 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 here like c++.

  6. python - How do I sort a dictionary by value? - Stack Overflow

    Mar 5, 2009 · I am writing this detailed explanation to illustrate what people often mean by "I can easily sort a dictionary by key, but how do I sort by value" - and I think the original post was trying to …

  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. How can I sort a list of dictionaries by a value of the dictionary in ...

    Python has supported the key= for .sort since 2.4, that is year 2004, it does the Schwartzian transform within the sorting code, in C; thus this method is useful only on Pythons 2.0-2.3. all of which are more …

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