A="HACK" k=2 for x in range(int(k)): D=list(combinations(a,x+1)) E=list(map(lambda y:print(*y,sep=\'\'),D)) This prints A C H K AC AH AK CH CK HK
A="HACK" k=2 for x in range(int(k)): D=list(combinations(a,x+1)) E=list(map(lambda y:print(*y,sep=\'\'),D))