Question:
Write a program to sort ‘GlobalSQA’ lexiographically
Program:
1 2 3 4 |
def lexicographi_sort(s): return sorted(sorted(s), key=str.upper) print(lexicographi_sort('GlobalSQA')) |
Explanation:
The lexicographic or lexicographical order (also known as lexical order, dictionary order, alphabetical order or lexicographical product) is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters. The sorted function sorts it for you.
Output:
1 |
['A', 'a', 'b', 'G', 'l', 'l', 'o', 'Q', 'S'] |
Leave a Reply