+ 2

str1 = "hello" str2 = "olleh" if two strings matches will return true otherwise false

If two strings same words of count will return true otherwise false - Not about length str1 = "hello" str2 = "olleh" output ={} output1={} for i in str1: output[i]=str1.count(i) for j in str2: output1[j]=str2.count(j) if str(output) in str(output1) : print("yes") else: print("No") Any idea?

21st Feb 2022, 5:40 AM
Manoj Bhaagam
5 Antworten
+ 5
You can try something like the below segment: if(str1.length==str2.length): for i in str1: if(str1.count(i)!=str2.count(i)) print("No"); //Exit here print("Y e s"); I don't know Python much, but you can see the structure of the code. First we're checking if the strings are equal in length, if yes then we're checking the count of each letter in str1 to str2. If anything doesn't match then we're printing "No". There you exit the function. If you came out of the if condition, then it means that everything has matched so far, so printing "yes"
21st Feb 2022, 5:50 AM
Rishi
Rishi - avatar
+ 2
G'day Manoj Bhaagam I'm not 100% but I think they want you to count the value of each letter in the string and compare. I'm sure there will be a pythonic way to do this, but I would take one letter at a time, add the ASCii value to my tally. I would then tally the second string in the same way. Then you can compare the two tallys. Eg tally1 =0 tally1 +=68 #ascii of h tally1 +=65 #ascii of e Etc etc ....
21st Feb 2022, 5:46 AM
HungryTradie
HungryTradie - avatar
+ 2
def word_count(a="hello",b='olleh'): out1 = {k:a.count(k) for k in a } out2 = {k:b.count(k) for k in b} return out1==out2 Hope this helps
21st Feb 2022, 1:41 PM
Pythøñ Cúltîst⚔️🔥🇳🇬
Pythøñ  Cúltîst⚔️🔥🇳🇬 - avatar