0
To check wheather n is formed from m
m in given as input.n is given as input. the program has to check wheather m is formed from the elements of n.. for eg 1 m=12345 n=45321 result = yes eg 2: m= 3456 n= 98 result =no
16 Answers
+ 2
Drunken Data as far as i can see your code doesn't take into account that they might be of different length, so as long as m contains n, your code will output yes. i'm about to see if i can make my own solution
+ 2
Drunken Data
https://code.sololearn.com/c5oynq838mDx/?ref=app
this works for me
+ 2
print(all([i in m for i in set(n)]))
+ 1
Drunken Data ok
+ 1
m='565'
n='555'
m={i:m.count(i) for i in m}
n={i:n.count(i) for i in n}
print(all([m[i]<=n.get(i,0) for i in set(m)]))
0
that's easy, you can just sort both and then check if they're the same
0
no for inputs like m=5665
n=555 not coming coz n has three 5's while m has two 5's the output should be no
but printing yes
0
Drunken Data it shouldn't print yes, because when you sort both they're 5566 and 555 respectively which aren't equal.
link your code please
0
I don't how to code with the method you sujjested but I have written a code in another way I will link up that
0
this is what I have written
0
pls check for your own inputs too
0
no this is not for input like m= 1234
n=23 are not working it's printing no but it should print yes because every digit in n is present in m so that n can be formed from m this is what I have to check
0
Drunken Data oh in that case your solution will work if you iterate the other way around
0
yeah it work for some test cases but in some cases like m=565
n=555 it's printing yes but it should be no coz in n it has three 5 but in m it has only two 5 .my program checks only whether the number in n is present in m but it's not checking for every digit ( espeacially for repeating digits)
0
I hope you understand what I am trying to say....yeah????