Reverse a string while maintaining the capitalization in the same places
Python, 71 bytes
lambda s:''.join((z*2).title()[c.isupper()-1]for c,z in zip(s,s[::-1]))
Try it online
-3 bytes from Ruud, plus the inspiration for 2 more.
-4 more bytes from FryAmTheEggman
Perl, 31 + 2 (-lp
) = 33 bytes
This solution is from @Ton Hospel (13 bytes shorter thant mine).
s%.%(lc$>$&?u:l)."c chop"%eeg
But you'll need l
and p
switches on. To run it :
perl -lpe 's%.%(lc$>$&?u:l)."c chop"%eeg'
Python 2, 73 bytes
Since the rules specify the input is ascii:
lambda s:''.join([z.lower,z.upper]['@'<c<'[']()for c,z in zip(s,s[::-1]))
All the credit goes to @Mego though, but I had not the reputation to just comment on his answer.