I have an input file - file.txt :
guten
('nine', 'november')
('six', 'nine')
0
end
My python program is:
aa = []
with open('file.txt', 'r') as F1:
for line in F1:
line = line.rstrip('\n')
aa.append(line)
print aa
I am getting the output as:
['guten', "('nine', 'november')", "('six', 'nine')", '0', 'end', '']
But my expected output is:
['guten', ('nine', 'november'), ('six', 'nine'), '0', 'end', '']
Can someone tell me where I am going wrong ? Your help will be useful. Thanks in advance.
()in the text file to turn into tuples, even though that text file is not Python code? But you want numbers to stay as strings?sorted(['b', 'a', 'f', 'd', 'e', (3, 4), 1, 4, 5])