I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can’t find any example code anywhere, except for specific code focusing on sorting date fields.
How would one go about sorting a relatively large CSV file (tens of thousand lines) on multiple fields, in order?
Python code samples would be appreciated.
Here’s Alex’s answer, reworked to support column data types:
Edit:
I did a stupid. I was playing with various things in IDLE and wrote a
convertfunction a couple of days ago. I forgot I’d written it, and I haven’t closed IDLE in a good long while – so when I wrote the above, I thoughtconvertwas a built-in function. Sadly no.Here’s my implementation, though John Machin’s is nicer:
Usage: