Merge the tools! | HackerRank | Python | String

preview_player
Показать описание
This video is about Merge the Tools! problem from HackerRank.

For 1 : 1 Tutoring
WhatsApp contact : 7278222619

#HackkerRank #Python #string
Follow me on:
Whatsapp:

Facebook:

Linkedin:

Instagram:
Рекомендации по теме
Комментарии
Автор

my approach :
def merge_the_tools(string, k):
mylist = []
m = 0
for x in range(len(string)//k):
mylist.append(string[m:m+k])
m += k

for x in mylist:


btw thanks coding cart for the help! wouldn't have been done without your explanation!

ElloBruh
Автор

started python abt 2 weeks ago and this video helped me to realise to use "dict()" to remove the non-distinct characters! thanks
Heres my solution:
```import textwrap

def merge_the_tools(string, k):
t = textwrap.wrap(string, k)
for i in t:

zerynn
Автор

Here's a diff approach :
from collections import OrderedDict

def merge_the_tools(string, k):
l = []
m=0
for i in range(len(string)//k):
l.append(string[m:m+k])
m= m+ k

for v in l:


tykioic
Автор

My Solution:
def merge_the_tools(string, k):
while string:
s = string[0:k]
there = ''
for c in s:
if c not in there:
there += c
print(there)
string = string[k:]

hureramujeeb
Автор

may god bless you bro..great explanation

anujpathak
Автор

After getting the substring and then converting it into a list, we could've use set() instead of creating a new dictionary and then again getting the key values. But again, I appreciate the explanation.

darpanshrivastava
Автор

here the different apporach of merge tools
string=input()
k=int(input())
s=len(string)//k

m=0
empty_list=[]
for i in range(s):

m+=k
sub_str=empty_list
for v in sub_str:

print(dict_keys)

sunillucky
Автор

Another Approach :

def merge_the_tools(string, k):
# your code goes here

w = len(string)
for i in range(1, int(w/k)+1):
lt = []
st = ''
new_string = string[k*i-k : k*i]
for j in new_string:
if j not in lt:
lt.append(j)
st = st + j
print(st)

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

tdyhuho
Автор

Very nice approach bro...keep it up :)

piyushchaudhari
Автор

hi is it possible to use set insted of dict as set will anyhow remove the duplicates

debojitmandal
Автор

Very Good Explanation Sir, Are You Software Employee

cricketh
Автор

Why hackerrank has to limit what you can do, how you will solve the problem? In the Merge The Tools problem, their given code can't be deleted. WTF!

Cloudxxx
Автор

Hi. You didn't explain why it need to convert to dictionary and the fromkeys method.🤔🤔😏😏

Cloudxxx
Автор

sir can we use set in this to remove duplicate

dhruvtrivedi
Автор

Don't you check for the constraint as well?

surajthadarai
Автор

bro how did you get the number of lines in your jupyter notebook ....plz tell me

abrarmasumabir
Автор

import textwrap
def merge_the_tools(string, k):
x=textwrap.wrap(string, k)
for i in x:

#### I just copy your code sir for making a list i use textwrap.wrap()

bibekanandasahoo
Автор

sir can we use textwrap function for it

reddyhimabindu
Автор

here is my approach

s ='AABCAAADA'
m=0
k =3
l=[]
for i in range(len(s)//k):
l.append(s[m:m+k])
m = m+k
l
for v in l:
print(v)
z = set(v)
print(z)
result_string = ''.join(z)
print(result_string)

debojitmandal