Printing a text centered, it would be a newbie prob

Steve Holden sholden at
Tue Jun 4 14:47:04 CEST 2002

"Backflip" <Backflip at> wrote in message
news:c7bfc769.0206040012.20aa0a10 at
> Hello World (=
> I´ve got a little problem, i want to put out an import string centert. For
> for word in raw_input("bitte hier ihren text eingeben:").split():
>    print word
> text=dies ist ein test
> now the output looks like this
> dies
> ist
> ein
> test
> but i want that it looks like this one
> dies ist
> ein test
> that both rows are simular to each other, could smb help me?

>From your description, are we to assume that you only want two rows of
output? Is the "similarity" referring to the number of words or the number
of characters? Since the former is easier, would this answer your problem:

>>> w = "this is an example".split()
>>> wl = len(w) // 2
>>> l1 = w[:wl]
>>> l2 = w[wl:]
>>> print "%s\n%s" % (" ".join(l1), " ".join(l2))
this is
an example

I suspect there will be more that you haven't yet told us, however: the
specification was not rigorous.

Steve Holden                       
Python Web Programming      

More information about the Python-list mailing list