[Tutor] priting keys and its values of a dictionary in a single row

Rohan Deshpande rohan.deshpande at gmail.com
Sat Apr 28 12:54:32 CEST 2007


Or, get rid of the extra variable and do:

for i in m.items():
  print i[0] + ',' + ",".join(i[1])

On 4/27/07, Bill Burns <billburns at pennswoods.net> wrote:
>
> Srinivas Iyyer wrote:
> > Dear group,
> >
> > I have a dictionary (huge) and there are 19K keys for
> > this dictionary. The values for the could be a max 19K
> > again.
> >
> > simpler version of it:
> >
> > mydict=
> >
> {'a':['apple','ant','anchor','arrow'],'b':['ball','baby',boy','bus'],'c':['cat','call']}
> >
> > in a different list, i have keys:
> > mlist = ['a','b','c']
> >
> > I want to print in the following way:
> > a,apple,ant,anchor,arrow
> > b,ball,baby,boy,bus
> > c,cat call
> >
> > I cannot think of a simple way to do that (may be a
> > mental block). could any one help me please.
> >
> > Thanks
> > srini
> >
>
> Try this:
>
> for key in mlist: print '%s,%s' % (key, ','.join(mydict[key]))
>
> Bill
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070428/a27c404d/attachment.htm 


More information about the Tutor mailing list