About 3,260,000 results
Open links in new tab
  1. How to Sort a Set of Values in Python? - GeeksforGeeks

    Apr 4, 2025 · This example demonstrates how to use the reverse=True parameter to sort data in descending order, along with the regular sorted() function. Python a = [ "geeks" , "for" , "geeks" ] print ( "without key parameter:" , sorted ( a )) print ( "with len as key parameter:" , sorted ( a , reverse = True ))

  2. Python list sort in descending order - Stack Overflow

    Mar 16, 2023 · Passing a function to list.sort: def foo(x): return time.strptime(x, '%Y-%m-%d %H:%M:%S')[0:6] timestamps.sort(key=foo, reverse=True)

  3. python - Sorting a set of values - Stack Overflow

    Jul 3, 2013 · The best solution is most likely to store the numbers as numbers rather than strings in the first place. But if not, you just need to use a key function: >>> sorted(s, key=float) ['0.000000000', '0.009518000', '0.018384000', '0.030810999', '4.918560000', '10.277200999']

  4. sort() in Python - GeeksforGeeks

    Jul 25, 2024 · The sort() method in Python is a built-in function that allows us to sort the elements of a list in ascending or descending order and it modifies the list in place which means there is no new list created.

  5. Python Sort List – How to Order By Descending or Ascending

    Sep 3, 2021 · In Python, you can sort data by using the sorted() method or sort() method. In this article, I will provide code examples for the sorted() and sort() methods and explain the differences between the two.

  6. How to Sort a Set in Python - Delft Stack

    Feb 2, 2024 · If you want to sort a set in descending order, you can convert the set to a list and then use the sort() method with the reverse=True parameter to sort the list in descending order. Here’s how you can do it:

  7. Sorting Techniques — Python 3.13.3 documentation

    5 days ago · Both list.sort() and sorted() accept a reverse parameter with a boolean value. This is used to flag descending sorts. For example, to get the student data in reverse age order: Sorts are guaranteed to be stable. That means that when multiple records have the same key, their original order is preserved.

  8. Sort a Set in Python - SkillSugar

    Mar 7, 2022 · Sort a Set in Descending Order Example. Here is another example, this time sorting a set into descending order using the reverse attribute in the sorted() function: s = {11, 5, 7, 1, 9} res = sorted (s, reverse = True) print (res) [11, 9, 7, 5, 1] Note - If you convert the result back to a set after completing the descending order operation it ...

  9. How To Sort A Set In Python? - ANSWERTICA

    Jan 22, 2025 · The sorted() function can be used to easily sort a set in Python by specifying the reverse parameter. This allows you to sort the set in descending order. By setting reverse=True, the sorted() function will arrange the elements from largest to smallest.

  10. The Python Sort List Array Method – Ascending and Descending Explained ...

    Apr 12, 2020 · The sort() method lets you sort a list in ascending or descending order. It takes two keyword-only arguments: key and reverse . reverse determines if the list is sorted in ascending or descending order.

  11. Some results have been removed
Refresh