Merge the Tools!

Sort by

recency

|

2644 Discussions

|

  • + 0 comments
    from textwrap import wrap
    
    def clean(s):
        seen = set()
        cleaned = []
        for c in s:
            if c not in seen:
                seen.add(c)
                cleaned.append(c)
        return ''.join(cleaned)
    
    def merge_the_tools(string, k):
        # your code goes here
        split = wrap(string, k)
        for s in split:
            print(clean(s))
    
    if __name__ == '__main__':
        string, k = input(), int(input())
        merge_the_tools(string, k)
    
  • + 0 comments

    Here is hackerrank merge the tools! solution in python - https://programmingoneonone.com/hackerrank-merge-the-tools-solution-in-python.html

  • + 0 comments

    Here is my proposed solution. It does not use set or dict as set is does not ensure ordering, and dict, before Python 3.7 does not preserve order as well:

    from collections import OrderedDict
    
    def merge_the_tools(string, k):
        subs = list()
        cutter = 0
        while cutter < string.__len__():
            subs.append(string[cutter : cutter + k])
            cutter += k
        
        for item in subs:
            print("".join(OrderedDict.fromkeys(item)))
            
    
    if __name__ == '__main__':
        string, k = input(), int(input())
        merge_the_tools(string, k)
    

    This ensures "All characters in the individual subsequence preserve their order" while ensuring we don't traverse the strings in individual loops.

  • + 0 comments
    import textwrap``
    def merge_the_tools(string, k):
        # your code goes here
        chunks = textwrap.wrap(string, k)
        for a in chunks:
            print(''.join(list(set(a))))
    
  • + 0 comments

    import textwrap def merge_the_tools(string, k): # your code goes here chunks = textwrap.wrap(string, k) for a in chunks: print(''.join(list(set(a))))