My lessons with python continues and im stuck with this exercise where i have such csv:
John^Reporter^Angola Mary^Engineer^Canada Anna^Manager^India and would like to achieve this:
Angola^John^Reporter Canada^Engineer^Mary Anna^India^Manager so every row is sorted by content in column from left to right.
I tried with this code:
with open('file.csv', 'r') as sortrow: reader = csv.reader(sortrow.readlines(), delimiter='^') reader = sorted(reader, key=lambda x: x[0]) with open(syspath+temppath+'/added5.csv', 'w') as sortwrite: writer = csv.writer(sortwrite, delimiter='^') for row in reader: writer.writerow(row) i thought sorted(reader, key=lambda x: x[0]) will do the job but its not. Please help. Thanks in advance