About 1,870,000 results
Open links in new tab
  1. python - Sort a list of lists based on an if/else condition - Stack ...

    def sort_col_value(row): # if first index is 0, sort on index nr 7. if row[0] == 0: return row[7] # Then if second index is 0, sort on index nr 8 if row[1] == 0: return row[8] return row[0] then use this …

  2. python - How do I sort 4 numbers using only conditionals (no …

    We were tasked to sort four integer inputs in descending order, and then the program should indicate the order you keyed in the inputs as well. For example: Input: 5, 10, 3, 3 Output: (1) …

  3. python - Sorting a list by conditional criteria - Stack Overflow

    Apr 28, 2017 · mylist.sort(key=lambda x: (len(x.split())>1, x if len(x.split())==1 else int(x.split()[-1]) ) ) Explanation: First condition len(x.split())>1 makes sure that multi word strings go behind …

  4. How to arrange the numbers in ascending order in python using

    Aug 20, 2019 · list=[7,4,6,6,3,10,7] for i in range(len(list)-1): for i in range(len(list)-1): if (list[i]>list[i+1]): list[i],list[i+1]=list[i+1],list[i] # the for loops can be replaced by list.sort() My …

  5. How to Sort Lists by Certain Conditions in Python

    Mar 15, 2022 · We can sort lists in Python using either the .sort() method. list1 = [2,4,3,1] list1.sort() # list1 will be [1,2,3,4] However, sometimes we need to sort a list by a certain …

  6. Sorting Techniques — Python 3.13.3 documentation

    Apr 27, 2025 · In this document, we explore the various techniques for sorting data using Python. A simple ascending sort is very easy: just call the sorted() function. It returns a new sorted list: …

  7. How to Use sorted() and .sort() in Python – Real Python

    Feb 24, 2025 · In Python, you can sort iterables with the sorted() built-in function. To get started, you’ll work with iterables that contain only one data type. You can use sorted() to sort a list in …

  8. Python List sort() | All Use Cases Explained (+Code Examples)

    Learn everything about Python's list sort () method, its syntax, parameters, and use cases. From sorting numbers and strings to complex data structures, master it all with clear examples and …

  9. [Class 11] Important programs in Python - Code + Examples

    Dec 13, 2024 · Program to sort 3 numbers in descending order using if-else statements. a = int(input( "Enter first number: " )) b = int(input( "Enter second number: " )) c = int(input( "Enter …

  10. Python Program to Sort List in Ascending Order - Tutorial …

    Sorting the integer List in ascending order output. In this program, we are using Nested For Loop to iterate each number in a List, and sort them in ascending order. value = int(input("Please …

Refresh