Reputation: 5261
I have a problen when I try to print the result of a function several times. lets say for example that after several commands the result is that dreawing
()()()
()()
()
now I want to duplicate it according to a function so i used a loop but it will only print it again in a vertical way like that:
()()()
()()
()
()()()
()()
()
()()()
()()
()
while I want it to be horizontal like that:
()()() ()()() ()()()
()() ()() ()()
() () ()
can you help me??
Upvotes: 1
Views: 365
Reputation: 10592
Here is a working solution to your problem.
lines = [
"()()()",
" ()()",
" ()"
]
def replicate(lines, n):
width = reduce(max, map(len, lines))
return (' '.join([line.ljust(width)] * n) for line in lines)
for line in replicate(lines, 3):
print line
edit: added spacing management
edit2: used a generator expression because of peer pressure :-)
Upvotes: 4