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.
def merge_the_tools(string, k):
# your code goes here
while string:
s = string[0:k]
seen = ''
for c in s:
if c not in seen:
seen += c
print(seen)
string = string[k:]
string = string[k:] -- This code dynamically splices the string k chunks,alternately you can do something like
[ s[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
And then iterate over this list of chunks
2. seen stores the unique list. If the alphabet is not present n seen, it will be added.This is done for all the chunks, reseting seen for each iteration.
defmerge_the_tools(string,k):# while loop runs till the string becomes emptywhilestring:# splice the given strings=string[0:k]# initiate an empty string# (seen is just the name of our variable)seen=''# run a for loop through our spliced string (s),# appending only unique characters to our variable seenforcins:ifcnotinseen:seen+=cprint(seen)# remove the spliced part from original string for the next iterationstring=string[k:]
I like Your solution. I made it somehow similiar to what you did. I add that I learn python 3rd day, so if someone see the problem in the code, all the comments are much appreciated.
def merge_the_tools(string, k):
for i in range (int(len(string)/k)):
s = string[i*k:(i+1)*k]
result = ''
for j in range (0 ,k):
if s[j] not in result:
result += s[j]
print (result)
wont non continous letters also get appended to seen which breaks one of the criteria?
all test cases passed tho :)
so i dont think the question isproperly framed
Merge the Tools!
You are viewing a single comment's thread. Return to all comments →
My solution:
simplest possible
I don't understand
what is the logic of the while loop here, when it will break ??
when the splicing is over
what does c do in for c in s:
c is an iterator which iterates character by character over the substring s
That c iterates over each character in the string 's'.
Chandan, let me explain:
[ s[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
And then iterate over this list of chunks 2. seen stores the unique list. If the alphabet is not present n seen, it will be added.This is done for all the chunks, reseting seen for each iteration.
It means run the loop the string is not None.
That's a very good solution
really great and simple solution
this code is brillent and easy to know how the code is work.. absolutly genius
Simple and less complex
Elegant solution!
seen = ' ' is not something I am familair with, can you please explain the logic here?
I like Your solution. I made it somehow similiar to what you did. I add that I learn python 3rd day, so if someone see the problem in the code, all the comments are much appreciated.
def merge_the_tools(string, k):
beautiful approach
wont non continous letters also get appended to seen which breaks one of the criteria? all test cases passed tho :) so i dont think the question isproperly framed
string = string[k:] superb
you = 'super awesome'
simple and straightforward. thanks for sharing
Excellent code, in this we dont have to use things like OrderedDict etc !