I have sentences,in a form of a string, that look like this :
First sentence
hund
barked 4.51141770734e-07
bit 0.0673737226603
dog 0.932625826198
Second sentence
hyi
biid 6.12323423324e-07
bok 0.0643253
dyfs 0.514586321
and I want to write them into columns into a file like this :
hund hyi
barked 4.51141770734e-07 biid 6.12323423324e-07
bit 0.0673737226603 bok 0.0643253
dog 0.932625826198 dyfs 0.514586321
Instead of having them like this :
hund
barked 4.51141770734e-07
bit 0.0673737226603
dog 0.932625826198
hyi
biid 6.12323423324e-07
bok 0.0643253
dyfs 0.514586321
Any ideas?
If it's string formatting you're after, you might want to look as str.ljust to make a string a certain length.
Suppose you have two lists of lines,
lines1
andlines2
. If you have a string with multiple newlines, you can make a list of lines by calling.split('\n')
.Then, you can format them into parallel columns with string formatting:
Example:
Output: