About 50 results
Open links in new tab
  1. Sort python list by function - Stack Overflow

    Aug 21, 2011 · 2 A lambda function is useful if your sorting function takes a support argument, otherwise function name is enough. For example, if you want to sort list of string representation of datetime by …

  2. python - What is the difference between sorted (list) vs list.sort ...

    The .sort () function stores the value of new list directly in the list variable; so answer for your third question would be NO. Also if you do this using sorted (list), then you can get it use because it is not …

  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. What arguments does Python sort() function have? - Stack Overflow

    Dec 29, 2009 · Sequences can contain any objects, not even comparable, but if we can define a function which produces something we can compare for each of the items, we can pass this function in key …

  5. How does the key argument in python's sorted function work?

    The function you pass in to key is given each of the items that are being sorted, and returns a "key" that Python can sort by. So, if you want to sort a list of strings by the reverse of the string, you could do this:

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

  7. python - Sort a list of lists with a custom compare function - Stack ...

    I have a list of lists, 50 times 5 elements. I want to sort this list by applying a custom compare function to each element. This function calculates the fitness of the list by which the elements shall be sorted. I …

  8. Order a list of numbers without built-in sort, min, max function

    6 This strictly follows your requirements not to use sort(), min(), max() but also uses Python best practice by not re-inventing the wheel.

  9. python - How to sort a list/tuple of lists/tuples by the element at a ...

    @Cemre as for the second example, sort here is a method of List object of Python, which receives a lambda function as its key parameter. You may name it as tup, or t, or whatever you like and it'll still …

  10. Why does '.sort()' cause the list to be 'None' in Python?

    Mar 20, 2012 · You don't need a custom function for what you want to achieve, you first need to understand the methods you are using! sort() ing a list in python does it in place, that is, the return …