1

I'm trying to do this assignment:

This is what I have and I am getting a syntax error on >

Pasted code:

# Specify where the input and output file is

InputFile = open('C:\Python\unsorted_fruits.txt', 'r')
OutputFile = open('C:\Python\sorted_fruits.txt', 'w')

# Read the input file

Fruits = InputFile.readlines()

# Sort the items in the list
Fruits.sort()

# Remove the blank lines and write the file
for fruit in Fruits:
    if fruit <>"\n":    # if fruit is blank, skip the write
        OutputFile.write(fruit) # otherwise write the fruit to the output file


# Close the input and output file
InputFile.close()
OutputFile.close()
4
  • 1
    if fruit <>"\n": What the heck are you doing? Commented Dec 30, 2015 at 1:41
  • Oh, is that what that is? What language uses that? Commented Dec 30, 2015 at 1:43
  • 2
    Isn't <> like some deprecated syntax for != Commented Dec 30, 2015 at 1:51
  • 1
    Worth a read: stackoverflow.com/a/15233739/2308683 Commented Dec 30, 2015 at 2:40

1 Answer 1

1

Just replace "<>" with "!=", since "<>" is deprecate in python3,which can be used as "!=".

Sign up to request clarification or add additional context in comments.

1 Comment

Was <> ever used in Python? o_O I didn't ever see it anywhere outside BASIC.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.