We tried to solve the following problem with friends but we couldn't come to a conclusion. How can we approach this question?
The full question is:
Even Words Problem: An even word is a word that contains an even number of copies of every letter. For example, the word "tattletale" is an even word, since there are four copies of 't' and two copies of 'a,' 'e,' and 'l.' Similarly, "appeases" and arraigning" are even words. However, "banana" is not an even word, because there is just one 'b' and three copies of 'a.'
Write a function
def isEvenWord(word)
that accepts as input a string representing a single word and returns whether or not that word is an even word.Your solution should be recursive and must not use any loops (e.g. while, for). As a hint, this problem has a beautiful recursive decomposition:
• The empty string is an even word, since it has 0 copies of every letter.
• Otherwise, a word is an even word if there are at least two copies of the first letter and the word formed by removing two copies of the first letter is itself an even word.
For example, we can see that the word "appeases" is an even word using the following logic:
"appeases" is an even word, because "ppeses" is an even word, because "eses" is an even word, because "ss" is an even word, because "" is an even word.