My code takes the input and successfully writes to the 'data.csv' file, but whenever more than one number is entered as the initial input (e.g. '98765 12345') I get IndexError: list index out of range
on the very last line.
Can anyone see where I'm going wrong?
x = raw_input('Enter numbers separated by a space: ')
new_FONs = [[int(i)] for i in x.split()]
with open('data.csv', 'a+') as f:
writer = csv.writer(f)
writer.writerows(new_FONs)
with open('data.csv', 'r') as f:
all_FONs_str = [line.split() for line in f]
all_FONs = [[int(FON[0])] for FON in all_FONs_str]
for FON in new_FONs:
# Count the occurence of this number in the CSV file
FON_count = all_FONs.count(FON)
if FON_count == 1:
print('once')
elif FON_count == 2:
print('twice')