[C++-sig] len(list())?
David Abrahams
david.abrahams at rcn.com
Wed Jul 3 15:42:37 CEST 2002
----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>
To: <c++-sig at python.org>
Sent: Wednesday, July 03, 2002 9:34 AM
Subject: Re: [C++-sig] len(list())?
> --- David Abrahams <david.abrahams at rcn.com> wrote:
> > It works if you substitute "object" for "dictionary", as I suggested.
>
> Yes, indeed. Thanks.
>
> The context:
>
> // restore the object's __dict__
> object odict(mydict);
> object pdict(state_[0]);
> list pkeys(dictionary(mydict).keys());
> for(std::size_t i=0;i<len(pkeys);i++) {
> odict[pkeys[i]] = pdict[pkeys[i]];
> }
>
> What can be said about
>
> odict[pkeys[i]] = pdict[pkeys[i]];
>
> versus
>
> object k(pkeys[i]);
> odict[k] = pdict[k];
Not much. Mostly that the latter is more-efficient.
But why don't you rewrite the whole thing:
odict.attr("update")(pdict);
When we have a dict class you'll be able to write
odict.update(pdict)
Isn't it nice to be able to write Python in C++ <.002 wink>?
-Dave
More information about the Cplusplus-sig
mailing list