Reputation: 49
I want my output file format to be like this :
file_out.write("{0},{2},{3},{4},{5},{6},{7},{8},{9},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29}\n".format(*frequency_count(seq)))
Basically I want to write a file that contains item one until 30 . I tried to do something like this
file_out.write("{0}:{29}\n".format(*frequency_count(seq)))
but i only get the 1st item and the last item. How do I write such that my output file contains all items without having to write all of them in my command.
The items are integers from a list of something.
Upvotes: 1
Views: 66
Reputation: 2682
Try this:
for i in range(30):
write_me += '{%d},' % i
write_me += '\n'
file_out.write(write_me).format(*frequency_count(seq))
It should work just ask questions below.
EDIT: Just realized I misunderstood the question disregard thsi
Upvotes: 0
Reputation: 2555
Assuming you want the first 30 items returned from frequency_count comma-delimited, try the following:
file_out.write(','.join(map(str,frequency_count(seq)[:30])) + '\n')
Upvotes: 3
Reputation: 473873
You can simply join items by ,
:
file_out.write(','.join(frequency_count(seq)))
You may also need to cast list items to string before joining:
file_out.write(','.join(map(str, frequency_count(seq))))
Upvotes: 1