|
|
|
|
|
by imauld
3445 days ago
|
|
And in Python: with open("foo.txt.") as f:
foo = sorted(list(set(line.strip() for line in f]))) with is a context manager that will automatically close the file once it's out of scope, not required but it's much cleaner and safer. Should the code change you don't have to worry about the call to close the file getting lost. The call to set() could be replaced with a set comprehension, {i for i in sequence}, but for clarity I used set(). It's certainly not the most efficient way to do it but it's simple and clear. |
|