count palindrome string | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

count palindrome string

The palindromic score of a string is the number of errors(characters which do not match) when the string is read forwards and backwards. For example, the palindromic score of ā€˜foxā€™ is 2, because ā€˜foxā€™ and ā€˜xofā€™ differ by two characters. Write a function to take a string and return its palindromic score. //output aa=0 aabb=0 aaabbb=6 abcde=5 // please write return statement

26th Apr 2021, 6:47 AM
Pavan priya
Pavan priya - avatar
6 Respostas
+ 3
1. You didn't tag a language 2. Your output explanation doesn't make sense when compared to the description of the problem. aabb = 0? Wouldn't this be 4 and abcde = 5? Then how is fox 2 and not 3 3. Where is your attempt at solving the problem? Try it yourself first and post your code if you can't figure it out. Hint: Take the original string and a reversed copy of the string and loop over the characters comparing them to each other, increment a counter when they differ.
26th Apr 2021, 7:16 AM
ChaoticDawg
ChaoticDawg - avatar
0
sum([ 0 if a==b else 1 for a, b in zip(word,word[::-1]) ])
26th Apr 2021, 7:36 AM
Oma Falk
Oma Falk - avatar
0
Jan Markus a kind of counter should be better
26th Apr 2021, 7:42 AM
Oma Falk
Oma Falk - avatar
0
Frogged You actually only need to go over the first half of the strings if you increment by 2 šŸ˜‰
26th Apr 2021, 7:50 AM
ChaoticDawg
ChaoticDawg - avatar
0
ChaoticDawg perfect!
26th Apr 2021, 8:44 AM
Oma Falk
Oma Falk - avatar
0
Where I could find the answers for this
24th Aug 2021, 4:19 PM
hima bindu
hima bindu - avatar