python equivalent of php implode

Jeff Epler jepler at unpythonic.net
Wed Apr 27 09:34:41 EDT 2005


On Tue, Apr 26, 2005 at 09:59:29PM -0500, Mike Meyer wrote:
> Jeff Epler <jepler at unpythonic.net> writes:
> 
> >     items = query_param.items()
> >     keys = [item[0] for item in items]
> >     values = [item[1] for item in items]
> 
> Is there some reason not to do:
> 
>    keys = query_params.keys()
>    values = query_params.values()
> 
> That would seem to be a lot more obvious as to what was going on.

I was afraid that .keys() and .values() might not "match up" (so that
the i'th key maps to the i'th value in query_param).  Now that I've
glanced at the documentation, I see that this *is* guaranteed[1], and
I should have written the code you proposed.

Jeff
[1] http://docs.python.org/lib/typesmapping.html note 3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050427/73c5404f/attachment.sig>


More information about the Python-list mailing list