(Jun-11-2018, 09:13 AM)perfringo Wrote: You are totally correct!
OP asked: "how could I use list comprehension to create a list that exclude the first row that contains header?"
There are also non-redundant ways of using list comprehension:
without_header = [v for i, v in enumerate(my_list) if i > 0]or
without_header = [row for row in my_list if my_list.index(row) > 0]
A person asking question sometimes over-complicates possible solution due to lack of knowledge (not a sin). Those who know better may show a better way - instead of showing a wasteful code just to
prove the point
- and that is a sin Since slicing produces a
list
, it's somewhat obvious that slice may be used as a source for list comprehension.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.