Dictionary from list?
Quinn Dunkan
quinn at hurl.ugcs.caltech.edu
Mon Oct 22 03:19:46 EDT 2001
On Sat, 20 Oct 2001 01:14:46 GMT, Jim Correia <jim.correia at pobox.com> wrote:
>> Hopefully you and everyone who reads your code has all
>> the little details in the camel book memorized.
>
>I was just asking if there was a built in coercion available.
>(Coercions aren't unheard of in scripting languages.) This wasn't a my
>language is better than your language war. I don't have particularly
>strong feelings about perl or python one way or the other (I do most of
>my work in compiled languages - C mostly) but use the right tool, or
>sometimes the convenient tool, for the job.
Sorry if I came across as a jerk. I read more into your post than you
intended.
Dynamic languages generally can't convert at assignment because there are no
declarations to tell them what to convert to (perl's @$% are effectively type
declarations). Python's '=' has a different philosophy than a C++-ish
operator= anyway.
The only way to coerce things is to explicitly call the coerce() function on
them. Python's built-in operators do this for numeric types, but that's about
it. You can also give objects a __coerce__ method. But it really doesn't do
the sort of thing I think you mean when you say "coerce".
I think a list->dict converter would be a perfectly reasonable addition to the
library, but it's not there to my knowledge.
There is a built-in function in mxTools, but it expects a list of tuples and
it's not the the stdlib anyway.
More information about the Python-list
mailing list