Beginning programmer question - How to print a list in a differentformat

Robert Brewer fumanchu at amor.org
Fri Feb 6 21:47:58 EST 2004


John wrote:
> p1hand = 
> {'b12':b12,'d12':d12,'d23':d23,'n12':n12,'n23':n23,
> 'n34':n34,'p12':p12,'p23':p23,'p34':p34,'p45':p45}
> p1handlist = p1hand.keys()
> print p1handlist
> 
> ['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

Hi, John,

Try the following:

p1handlist = p1hand.keys()
p1handlist.sort()
print ', '.join(p1handlist)


HTH,

Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list