The best way to change the letters "A" and "B" in places
📁 функция, python, пример
There is a function that takes an argument in the form of a line consisting of ““ a ”,“ a ”,“ b ”” and “b”.
each “b” should be replaced by “a”, each “a” ““ B ”” and also with the lower registry. Class = ""> wrote such a weak code, but the working: & gt; & gt; Swap ( '"aabbbaa' ) '' BBAAAAABB ' def swap ( text ): New_text = [] for c in text: if c == '`` `` : new_text.append ('б') elif c == 'б': new_text.append('а') elif c == 'a' : news_text.ppend class = ""> 'b' : New_text.append ( 'a' ) retu '' .join (New_text)
How can this problem be solved in another way so that the code is shorter and/or faster?