Issue
N | l1 | l2 | l3 | l4 | l5 |
---|---|---|---|---|---|
l1 | 1 | 2 | 3 | 4 | 5 |
l2 | 2 | 4 | 6 | 8 | 10 |
l3 | 3 | 6 | 9 | 12 | 15 |
l4 | 4 | 8 | 12 | 16 | 20 |
l5 | 5 | 10 | 15 | 20 | 25 |
this needs to be the output of input list:(input list: l=[1,2,3,4,5]) I want to also publish the output grid in a csv.
Solution
You can use a nested list comprehension.
import csv
l = [1,2,3,4,5]
table = [[a*b for b in l] for a in l]
with open("output.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(table)
Answered By - Unmitigated
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.