yeon
yeon I am a Korean web programmer with bboy dancing as a hobby. :)

Merge the Tools!

Merge the Tools!

hacker rank



Python Practice


Merge the Tools!


The first line contains a single string denoting s.
The second line contains an integer, k, denoting the length of each subsegment.


Sample Input

1
2
AABCAAADA
3


Sample Output

1
2
3
AB
CA
AD



My code


1
2
3
4
5
6
7
8
9
10
11
12
13
def merge_the_tools(string, k):
    splitNum = len(string)/k;
    for i in range(0, len(string), k):
        str = string[i:i+k];
        sub = ''
        for s in str:
            if s not in sub:
                sub += s;
        print(sub);

if __name__ == '__main__':
    string, k = input(), int(input())
    merge_the_tools(string, k)  



Hacker Rank > Python > String > Merge the Tools!

comments powered by Disqus