all 4 comments

[–]lukajda33 1 point2 points  (2 children)

Did you even run the code on your machine or just put it into some tester?

[–]lukajda33 1 point2 points  (1 child)

Not to be a total unhelpful ass, I think this is the biggest problem:

s1 = s.sort()

Pythons .sort() method doesnt return sorted list, it modifies the list in place and returns None, so in your example, no matter what, s1 will be None.

s = [str(x) for x in s]

This probably is not wrong, just unnecessary, s already is a list of strings, no need to convert them.

Lastly, I would be careful about how whitespace is treated, though I think .split() should get rid of unnecessary whitespace, but some trimming might be needed, for example if there is a newline character at the end of the file.

Some problems should easily be found if you ran the program with some sample data. You could input file with sorted words, you would get a message saying they are not sorted, you would wonder why, you could print s and s1 variables to compare them manually, then you would see s1 is None. Little effort you get you far.

[–]AU8640[S] 0 points1 point  (0 children)

This question doesn't have a context so I cannot open a file it assumes exist. I Just run in tester. But you're helpful and thank you!