Problem :

https://www.hackerrank.com/challenges/big-sorting/problem


My Solution :

#!/usr/bin/env python3

def bigSorting(unsorted):
    dic = {}
    ret = []
    for s in unsorted:
        dic.setdefault(len(s), []).append(s)
    for k in sorted(dic):
        for s in sorted(dic[k]):
            ret.append(s)
    return ret


n = int(input())
unsorted = []
for _ in range(n):
    unsorted_item = input()
    unsorted.append(unsorted_item)
result = bigSorting(unsorted)
for s in result:
    print(s)


My Solution2 :

#!/usr/bin/env python3

def bigSorting(unsorted):
    return sorted(unsorted, key=lambda x:(len(x), x))


n = int(input())
unsorted = []
for _ in range(n):
    unsorted_item = input()
    unsorted.append(unsorted_item)
result = bigSorting(unsorted)
for s in result:
    print(s)