Arrange by length and Alphabetic order



Problem to arrange by the string length and alphabetic order.



Example-1:


Input    : l = [ "one", "two", "three", "four", "five", "six"]
Output   : ['one', 'six', 'two', 'five', 'four', 'three']   


Example-2:


Input    : l = [ "four", "five", "six", "ten"]
Output   : ['six', 'ten', 'five', 'four']  







Solution




l = [ "one", "two", "three", "four", "five", "six"]

a = sorted(l)

k = []

z = []

for i in range(len(a)):

    k.append((a[i],len(a[i])))

n = sorted( k, key = lambda x:x[1])

for y in n:

    z.append(y[0])

print(z)



Output



['one', 'six', 'two', 'five', 'four', 'three']