How do I keep only values from the list when I am writing into a text file

Viewed 25

So currently, I have a nested list: [[91, 4.0], [116, 9.0], [117, 1.0], [118, 100.0], [134, 1.0], [144, 30.0], [162, 41.0]]

So when I write it into a txt file I just get the same exact list.

So how do I go from that to:

91 4.0
116 9.0
117 1.0
118 100.0
134 1.0
144 30.0
162 41.0
1 Answers

Try:

lst = [
    [91, 4.0],
    [116, 9.0],
    [117, 1.0],
    [118, 100.0],
    [134, 1.0],
    [144, 30.0],
    [162, 41.0],
]

with open("out.txt", "w") as f_out:
    for a, b in lst:
        print(a, b, file=f_out)

then out.txt will contain:

91 4.0
116 9.0
117 1.0
118 100.0
134 1.0
144 30.0
162 41.0
Related