There is a function that takes an argument in the form of a string consisting of "A", "a", "B" and "b".
Each "B" must be replaced by "A", each "A" by "B" and also with a lower register.
Example:
>> swap('ААббББаа') 'ББааААбб' Wrote such a weak code, but working:
def swap(text): new_text = [] for c in text: if c == 'а': new_text.append('б') elif c == 'б': new_text.append('а') elif c == 'А': new_text.append('Б') elif c == 'Б': new_text.append('А') return ''.join(new_text) Question: how can you solve this problem differently? So that the code is shorter and / or faster.