If I have a list of lists:
x = [['1','2','3'],['4','5','6'],['7','8','9']]
How do I iterate over these lists and print them to get the following output?
1, 2, 3
4, 5, 6
7, 8, 9
Try this:
for l in x:
print ', '.join(map(str, l))
Output:
1, 2, 3 4, 5, 6 7, 8, 9
You pretty much have it:
# python
x = [['1','2','3'],['4','5','6'],['7','8','9']]
for i in x:
print i[0]
1
4
7
for i in x:
print i
['1', '2', '3']
['4', '5', '6']
['7', '8', '9']
for i in x[0]:
print i
1
2
3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With