I have a string with mixed cases, for example. "ABCDEF". I want all uppercase letters in uppercase, and for uppercase letters - only lowercase letters if they are the letter "B". I want to get the result "AbCDEF". I tried to do this in a list comprehension:
x = [str.upper(char) if char.islower()
else str.lower(char) if char == "B" for char in "aBcDeF"]
- Line breaks are for read only, in my code they connect
However, I get the following syntax error:
Traceback (most recent call last):
File "python", line 11
else str.lower(char) if char == "B" for char in "aBcDeF"]
^
SyntaxError: invalid syntax
I looked at similar questions, but no one gave me an answer.
source
share