Merge the Tools!

  • + 0 comments

    I didnt know about the textwrapper lib, so i created a batch function, similar to what happens on the itertools.batched (for some reason is not working here). Also, if im using python3 instead of pypi3, is not possible to use sets to remove duplicates, since the set doesnt keep the order of the elements resulting in wrong outputs. I did some research and found out that the order is kept in python 3.6 but i dont know wich version this IDE uses, so i did without set in a simple for.

    def batch(iterable, n):
        re = []
        re = [iterable[i: i + n] for i in range(0, len(iterable), n)]
        return re
    
    def merge_the_tools(string, k):
        subs = batch(string, k)
        result = ''
    
        # without set()
        for sub in subs:
            for s in sub:
                if s not in result:
                    result += s
            print(result)
            result = ''
            
        ## using set()
        # result = [set(s for s in sub) for sub in subs]
        # for r in result:
        #     print(''.join(r))