Merge the Tools!

  • + 66 comments

    I love Python for things like this:

    Python 3.x:

    S, N = input(), int(input()) 
    for part in zip(*[iter(S)] * N):
        d = dict()
        print(''.join([ d.setdefault(c, c) for c in part if c not in d ]))
    

    setdefault method returns the key value available in the dictionary and if given key is not available then it will provided default value and adds it to the dictionary.