Merge the Tools!

Sort by

recency

|

2649 Discussions

|

  • + 0 comments

    A simple Core Python code with descriptions (as comments), and without using any inbuilt function or module:

    ` def merge_the_tools(string, k):

    string_split= [string[characters : characters+k] for characters in range(0, len(string), k)]
    
    # ['ADA', 'AAB', 'CAA'] -- Otput of string_split will be something like this (assuming k=3 here)
    
    for word in string_split:
        l= []  
        for letter in word:        
            # print(letter) ['A', 'D' 'A']- 1st Iteration
            if letter not in l:
                l.append(letter) 
        # print(l) -- ['A','D']   ['A', 'B']   ['C', 'A'] 
        print("".join(l))
    

    if name == 'main': string, k = input(), int(input()) merge_the_tools(string, k) `

  • + 0 comments

    import textwrap as tp def merge_the_tools(string, k): s=tp.wrap(string,k) s1=[] for i in s: j=set(i) j=list(j) print("".join(j))

  • + 0 comments
    def merge_the_tools(string, k):
        """
        This is a simple solution of O(N) time complexity
        
        First, we start iterating through the string at step k, this goes through each substring
        
        define each substring using string splicing
        
        using the fromkeys method which is a class method in pythons dict type. Creates a new dictionary from a sequence of keys or in this case chars, this assigns None to each key, and also removes duplicates, but still keeps the order. The alternative would have been to use some sort of set casting but I've come to find that that doesn't preserve order. 
        
        Then we use the string method 'join' with an empty string as the delimiter (aka the string for which the method is called upon) to get our u
        """
        
        for i in range(0, len(string), k):
            substr = string[i: i+k]
            shaved = "".join(dict.fromkeys(substr))   
            print(shaved)
    
  • + 0 comments

    def merge_the_tools(string, k): for i in range(0,len(string),k): lst = list() for j in range(i,i+k): if string[j] not in lst: lst.append(string[j]) print(''.join(lst))

    # your code goes here
    

    if name == 'main': string, k = input(), int(input()) merge_the_tools(string, k)

  • + 0 comments

    def merge_the_tools(string, k): for i in range(0,len(string),k): lst = list() for j in range(i,i+k): if string[j] not in lst: lst.append(string[j]) print(''.join(lst))

    # your code goes here
    

    if name == 'main': string, k = input(), int(input()) merge_the_tools(string, k)