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.
CodePudding user response:
Done.
print(' '.join(sorted([letter if (ord(letter) -97) % 2 == 0 else letter.upper() for letter in str(input())],reverse=True)))