How to Initialize a sorted array in one line instead of creating the array and then sorting it?
.sort()
doesn't return the result. It sorts the given list in place, and so you have no access to it.
Instead, you can use sorted
:
print(sorted([i if (ord(i)-97)%2 == 0 else i.upper() for i in input()], reverse=True))
Or call sort
on a list you have assigned to a name:
lst = [i if (ord(i)-97)%2 == 0 else i.upper() for i in input()]
lst.sort(reverse=True)
print(lst)