I was solving the following problem on HackerRank.
Here's my solution -
from itertools import combinations a = input() ls = list(map(str, a.split())) for i in range(1, int(ls)+1): ls2 =  ls2 = list(map("".join, combinations(ls, i))) for elem in ls2: ls2[ls2.index(elem)] = "".join(sorted(elem)) ls2.sort() for char in ls2: print(char)
But I feel it's not very efficient as it uses 2 Lists and 2 nested loops.
Any suggestions as to how can I improve the code?