-1

I want to write this code in one line without using ; and exec

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)

and couldn't do that so i came up with 4 line like this

input_string = str(input())
array = []
for i in range(len(input_string)): array.append(input_string[i]) if (ord(input_string[i]) -97) % 2 == 0 else array.append(input_string[i].upper())
print(' '.join(sorted(array,reverse=True)))

please help me to write this code in one line. thank you all in advance.

Elahe M
  • 1
  • 1

1 Answers1

0

Done.

print(' '.join(sorted([letter if (ord(letter) -97) % 2 == 0 else letter.upper() for letter in str(input())],reverse=True)))
Elahe M
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 05 '22 at 07:41