Is there any simple way to find the Last Iteration of the for Loop in Python? I just want to convert a list to CSV.
Is there any simple way to find the Last Iteration of the for Loop in Python? I just want to convert a list to CSV.
To convert a list to CSV, use the join
-function:
>>> lst = [1,2,3,4]
>>> ",".join(str(item) for item in lst)
"1,2,3,4"
If the list already contains only string, you just do ",".join(l)
.