Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert zip lists to a txt file without using any libraries

for (a, b, c, d, e, f, g) in zip(A, B, C, D, E, F, G):
    result = ''.join([a,b,c,d,e,f,g])

# Write the file
with open("file.txt","w") as f:
    f.write(result)

This only gives one line instead of the whole result. The type of the result is shown below. May I know how to convert the whole result to a txt file? Thanks a lot.

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

<class 'str'>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to call f.write(result) in the loop. And append a newline to each line.

with open("file.txt","w") as f:
    for data in zip(A, B, C, D, E, F, G):
        result = ''.join(data)
        f.write(result + '\n')

There’s no need to spread the zipped tuples into variables if you’re just going to combine them back into a list. Just use the tuples directly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading