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
|
2609 Discussions
|
Please Login in order to post a comment
def merge_the_tools(string, k): li=[] for i in range(0,len(string),k): temp="" for j in range(k): temp=temp+string[i+j] li.append(temp) dup=[] for i in li: temp="" for j in i: if j not in temp: temp=temp+j dup.append(temp) for i in dup: print(i)
def merge_the_tools(string, k): text = "" for i in string: text += i if len(text) == k: s = "".join(sorted(set(text), key=text.index)) print(s) text = ""
def merge_the_tools(string, k): # Iterate through the string in chunks of size k for i in range(0, len(string), k): # Extract the substring of length k s = string[i:i + k] # Remove duplicate characters while preserving order res = ''.join(dict.fromkeys(s)) print(res)
if name == 'main': string, k = input(), int(input()) merge_the_tools(string, k)