So I've written this code:
#input and output files
infile = open("unsorted_fruits.txt", "r")
outfile = open("sorted_fruits.txt","w")
#reading infile
Fruits = infile.read()
#time to sort the fruit
Fruits = Fruits.split()
Fruits.sort()
for fruit in Fruits:
if fruit != "\n":
outfile.write(fruit) #putting fruit in the output file
#closing files
infile.close()
outfile.close()
And, now I am trying to write pseudocode for it. I am having trouble getting pass the first line. I don't know how to word it? And every time I try to get help from the internet, bubble sort pops up, and I don't think that's correct. I could be wrong though.. Any input would be helpful. So far all I have before I get stuck is:
BEGIN insert both file names
READ unsorted_fruits.txt
EXECUTE
This process is entirely up to your wants and needs, unless you are doing a school project with specific guidelines.
going off of what you already have:
BEGIN insert both file names
READ unsorted_fruits.txt
ASSIGN lines in unsorted_fruits to variable Fruits
TURN Fruits into a list
SORT list of Fruits
ITERATE through list items(Fruits)
IF list item(Fruits) is anything but a newline, write
to outfile(sorted_fruits.txt)
CLOSE files