[Tutor] Question on joining out of order dictionary elements

Andre Engels andreengels at gmail.com
Thu Jan 11 14:34:52 CET 2007


2007/1/11, raghu raghu <vgvr620034 at gmail.com>:

> >>> print "\\".join((config["val2"],config["val1"],config["val3"]))
> elem2\elem1\elem3
>
> or
>
> >>> print "%s\\%s\\%s" % (config["val2"],config["val1"],config["val3"])
> elem2\elem1\elem3
>
> but this seems somehow uneligent.
>
> Are there a more efficient/compact ways of doing this kind of
> operation or is this it?
>

Maybe you like:
print "\\".join([config[val] for val in ["val2","val1","val3"]])

-- 
Andre Engels, andreengels at gmail.com
ICQ: 6260644  --  Skype: a_engels
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070111/86d36510/attachment.htm 


More information about the Tutor mailing list