r/pythonhelp • u/KeganBergi • Dec 08 '21
PYTHON ASSIGNMENT PLS SOMEONE LOL
Read in the included data file and write it to a file named sorted_data.txt with the same data, but order the columns in ascending alphabetical order.
https://www.dropbox.com/s/snhowdtcne6zuuf/MOCK_DATA-3.txt?dl=0
That is the link to the data file that is supposed to be initially read in.
1
Upvotes
1
u/[deleted] Dec 08 '21
Firstly, the wiki I mentioned, and my comments in general, were related to the r/learnpython subreddit - forgot where I was.
You can read the first row, as a header, using
next(whether simple text file or csv file).Now your
rowslist contains nested lists. You can sort on any entry using thekeyoption insorted. Keep in mind how different cases impact sorting.You could have using slicing instead to sort just
rows[1:], ignoring the header row. Look up list slicing.