Program to sort a list using for loop in Python.

In this program, we will sort a list using for loop in Python.

Steps to solve the program
  1. Take a list as input.
  2. Use for loop with range function to iterate over list values.
  3. Use a nested for loop to iterate over a value and remaining values of the list.
  4. If the selected value is greater than any value from the list then assign that element to a variable.
  5. Change the value of the grater value by smaller value and smallervalue by greater value.
  6. Print the output.
				
					l = [6,8,2,3,1,0,5]

for i in range(len(l)):
    for j in range(i,len(l)):
        if l[i]>l[j]:
            temp=l[i]
            l[i]=l[j]
            l[j]=temp
print(l)
				
			

Output :

				
					[0, 1, 2, 3, 5, 6, 8]
				
			

find the total number of special characters in a file

add elements from one list to another list and print It in descending order

Leave a Comment