def extract_and_sort_letters(line):
message = line[1::2]
uppercase_letters = sorted([char for char in message if char.isupper()], reverse=True)
if uppercase_letters:
return ''.join(uppercase_letters)
else:
return message
hidden_file = open('hidden.txt', 'r')
lines = hidden_file.readlines()
hidden_file.close()
opened_file = open('opened.txt', 'w')
for line in lines:
opened_file.write(extract_and_sort_letters(line) + '\n')
opened_file.close()