Kent Pawar
0
Q:

lexicographic order python

#code
def sortlexo(n):
    w = []
    for i in n:
        w.append(i)
    
    w.sort
    w = w[::-1]
    for i in w:
        print(i,end = "")
for i in range(int(input())):
    n= input()
    sortlexo(n)
0
my_arr = [
"hello",
"apple",
"actor",
"people",
"dog"
]

print(my_arr)
my_arr.sort()
print(my_arr)
0
my_arr = [
"hello",
"apple",
"actor",
"people",
"dog"
]

print(my_arr)
# Create a new array using the sorted method
new_arr = sorted(my_arr)

print(new_arr)
# This time, my_arr won't change in place, rather, it'll be sorted
# and a new instance will be assigned to new_arr
print(my_arr)
0

New to Communities?

Join the community