Beginning programmer question - How to print a list in a different format
John Matthews
John at the.computer
Fri Feb 6 23:28:09 EST 2004
In article <MPG.1a8e19663001709b989680 at news-server.columbus.rr.com>,
John at the.computer says...
> 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
>
> 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.
>
> Thanks!
>
> John
>
>
>
>
Robert & Andres,
Thanks so much for the help. As it turns out:
>>> print ', '.join(p1handlist)
does the trick! You have made me look like a genius! :)
John
More information about the Python-list
mailing list