May-15-2020, 04:57 PM
(May-14-2020, 11:52 AM)Rupini Wrote: is there other ways for me to achieve the same without CSV module?Yes you can write a own
csv.DictReader
implementation.Also if you look at csv module at top there is a link to Source code: Lib/csv.py .
So there can look at how they have written it,the important part start at line 119.
Here is start with some good hints,as this is homework there missing a little part.
lst = [] with open("log.csv") as f: header = next(f) header = header.strip().split(',') for row in f: row = row.strip().split(',') print(row)Look at what have now.
['xxx', 'uk', 'france'] ['yyyy', 'norway', 'finland'] ['zzzz', 'denmark', 'canada'] >>> header ['name', 'origin', 'dest'] >>> row ['zzzz', 'denmark', 'canada'] # Now can test line 119 >>> dict(zip(header, row)) {'name': 'zzzz', 'origin': 'denmark', 'dest': 'canada'}