I am taking an input file that contains lists of numbers with different statements separated by spaces and taking those numbers, adding two next to each other and printing out a word out if UTF-8. so if a list of numbers were 67 5 100 1 11 97 98 10 1 110
, the numbers would become 72, 101, 108, 108 and 111 which reads Hello in UTF-8.
I currently have the following code:
file_name = input('Enter filename: ')
input_file = open(file_name, 'r')
word_list = []
count3 = 0
for line in input_file:
count1 = 0
count2 = 1
count3 += 1
word_str = ''
line = line.split()
length = len(line)
while count1 < length:
num_char = int(line[count1]) + int(line[count2])
count1 += 2
count2 += 2
word_str += chr(num_char)
word_list.append(word_str)
print (word_list)
example input file:
67 5 100 1 11 97 98 10 1 110
15 72 10 101 47 67 88 20 94 6 22 11
61 11 93 4 73 39 78 34 17 104
23 43 11 93 65 52 20 96 66 31 86 24 40 61 102 13 50 51
73 43 28 73 8 89 31 68 77 27 24 77 42 72 15 24 64 51
25 75 7 90 10 111 17 16
From this code I get the output:
['Hello', 'World!', '', 'Happy', 'Bhutanese', "teacher's", 'day!']
My problem is that I need to sort the output in my list with the last statement first and the first statement last.
So for the provided numbers the expected output would read:
['Happy Bhutanese teacher's day!',
'Hello World!']
Any help is greatly appreciated