How can I write this code in one line? The concept is that you should:
- get one input from the user and check if the (ASCII form of the character) - 97 is divisible by 2 or not
- if yes, you should print the original form of the character
- else, you should print the upper case form of the character.
- last, you should reverse the answer.
- Example, if the input is
alexander
, the output should bee e a a X R N L D
- But it should be in one line and only one, I came up with a solution but it was 3 lines, I don't know what to do next.
This is the code I came up with so far:
h = []
for i in input() : h.append(i.lower() if (ord(i) - 97) % 2 == 0 else i.upper())
print(*sorted(h, reverse=True))
The original code for the question, which you should convert to one line is:
input_string = str(input())
array = []
for i in range(len(input_string)):
if (ord(input_string[i]) - 97) % 2 == 0:
array.append(input_string[i])
else:
array.append(input_string[i].upper())
array.sort(reverse=True)
answer = ' '.join(array)
print(answer)