Program to sort vowels in Python

Program to sort vowels in Python

In this section, we you will how to sort vowels in Python Programming in both ascending and descending order.

In this program, the given sequence must be sorted in ascending and descending order, i.e. the elements can be arranged in particular order. 

sort method: It is used to sort the elements of a given list in a specific order ascending or descending.

Syntax:

list.sort()


sort () parameters

By default, Sort () does not require any additional parameters. However, it has two optional parameters:

Reverse - if true, the sorted list will be reversed ( descending order).

Key - The function serves as the key to sort comparison.


sort () Return value 

The sort () method does not return any value. Instead, it changes the original list.

If you want a function to return the sorted list rather than changing the original list, use the sorted ().


Now take a look at how to write a program to sort vowels in Python Programming.

Python code:

vowels = ['e','i','a','u','o']
print("vowels before sorting=", vowels)
vowels.sort()
print("vowels in ascending order:",vowels)
vowels.sort(reverse=True)
print("vowels in descending order:", vowels)

Output:

vowels before sorting= ['e', 'i', 'a', 'u', 'o']

vowels in ascending order: ['a', 'e', 'i', 'o', 'u']

vowels in descending order: ['u', 'o', 'i', 'e', 'a']


Recommended Post:
Python Program to check vowel or Consonant
Program to check character is alphabet or not in Python
Python to check whether the year is leap or not
Python to check if number is Positive, Negative or 0
Python Program to solve Quadratic equation
Program to generate Random numbers in Python
Program to swap two numbers in Python
Program to Add two numbers in Python
Python to convert decimal to binary, octal and hexadecimal

Python Program to find large number among three numbers