Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Well, the tests are outrageously bad, so...
Oh my, it's really not a good solution... looks clever, but it isn't (in multiple ways)
You're right. Now I think that this is not a good solution in any case.
This will not work if the string contains an even number of duplicates of a word, or a word that is a reverse of another word in the string. Consider the input
stressed desserts
.In the first iteration of the
for
loop, all instances ofstressed
will be replaced withdesserts
, leavingstr
equal todesserts desserts
.In the second iteration, all instances of
desserts
will be replaced withstressed
, including thedesserts
introduced by the first iteration's replacement.This gives the incorrect output
stressed stressed
.If a word is repeated an even number of times, this solution will also reverse the reversal for that word.
I'm not sure what the intention is here: this will still throw an IndexError if len(a) < 2...