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.
- Prepare
- Python
- Strings
- Merge the Tools!
- Discussions
Merge the Tools!
Merge the Tools!
Sort by
recency
|
2615 Discussions
|
Please Login in order to post a comment
code
def merge_the_tools(string, k): text = "" for i in string: text += "".join(i) if len(text) == k: for i in range(len(text)): s = "".join(sorted(set(text), key=text.index)) print(s) text = ""
def merge_the_tools(string, k): l = textwrap.wrap(string,k) ll = {} for i in l: d = {k: "None" for k in list(i)} print("".join(list(d.keys())))
Can I use set function for this problem?
def merge_the_tools(string, k): #number of parts cnt = len(string) // k #list of parts l = [string[i*k : (i+1) * k] for i in range(cnt)] #process each part for s in l: print(''.join([ s[i] for i in range(k) if s[i] not in s[0:i] ]))
if name == 'main': string, k = input(), int(input()) merge_the_tools(string, k)