Beginning programmer question - How to print a list in a different format
Andres Rosado-Sepulveda
arosado at softhome.net
Fri Feb 6 22:56:02 EST 2004
John wrote:
> Hi.
>
> I have a dictionary thus: (wraps)
>
> p1hand =
> {'b12':b12,'d12':d12,'d23':d23,'n12':n12,'n23':n23,'n34':n34,'p12':p12,'
> p23':p23,'p34':p34,'p45':p45}
>
> I set a variable called p1handlist so that I can print a list of the
> keys to the screen:
>
> p1handlist = p1hand.keys()
> print p1handlist
>
> and the output looks like this:
>
> ['b12', 'd12', 'd23', 'n12', 'n23', 'n34', 'p12', 'p23', 'p34', 'p45']
>
> how can I make it so that the output looks more like this?:
>
> b12, d12, d23, n12, n23, n34, p12, p23, p34, p45
You can do something like this:
toPrint = ", ".join(p1handlist)
print toPrint
> This is for a simple text mode game I am writing and the output to the
> screen is important because at times the list gets too big to print on
> one line of the display.
You might want to split the list first and then join the sublists.
--
Andres Rosado
Email: andresr at despammed.com
ICQ: 66750646
AIM: pantear
Homepage: http://andres980.tripod.com/
Every election is a sort of advance auction sale of stolen goods.
-- H.L. Mencken
More information about the Python-list
mailing list