We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
defbatch(iterable,n):re=[]re=[iterable[i:i+n]foriinrange(0,len(iterable),n)]returnredefmerge_the_tools(string,k):subs=batch(string,k)result=''# without set()forsubinsubs:forsinsub:ifsnotinresult:result+=sprint(result)result=''## using set()# result = [set(s for s in sub) for sub in subs]# for r in result:# print(''.join(r))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Merge the Tools!
You are viewing a single comment's thread. Return to all 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.