0

I am attempting(can) write the values of a dictionary to files. The values are wrote in the file with the below format.

>foo bar
>too you

So each > represents a value within the key(file is the key) and also a line in the file.

Can I manipulate the values so that my file looks like this? (below)

>foo
bar
>too
you

Simply taking the white space in-between the strings of each value and making it into a return, is this possible?

I know that I could always read in the file again and strip the lines... but there are 100+ files from the output of my script, makes sense to do this "return" during the generation of the files.

The part of my code in question:

for key, values in sequencelist.items():
with open(key, 'w') as out:
    for value in values:
        out.write(''.join(value) + '\n')
4

1 回答 1

1
for key, values in sequencelist.items():
    with open(key, 'w') as out:
        for value in values:
            out.write('\n'.join(value.split()))
于 2013-04-12T21:20:12.697 回答