I'm trying to alphabetize items in a list while removing commas so as to format the lines from the list (text file) I'm using.
i'm required to use the while loop and not sure how i can incorporate the sort function to get the lines in alphabetical order
# open file
try:
f = open('animals.txt')
print('Success, file has been read\n')
except Exception:
print('Sorry. This file does not exist')
# display lines
print('Name\tPhylum\tDiet')
print('----\t------\t----')
inFile = open('animals.txt', 'r')
line = inFile.readline()
while (line):
print(line, end='')
line = inFile.readline()