Method much slower than function?
josiah.carlson at sbcglobal.net
Thu Jun 14 21:15:55 CEST 2007
sjdevnull at yahoo.com wrote:
> On Jun 14, 1:10 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>> "sjdevn... at yahoo.com" <sjdevn... at yahoo.com> writes:
>>> take virtually the same amount of time on my machine (2.5), and the
>>> non-join version is clearer, IMO. I'd still use join in case I wind
>>> up running under an older Python, but it's probably not a big issue here.
>> You should not rely on using 2.5
> I use generator expressions and passed-in values to generators and
> other features of 2.5.
For reference, generator expressions are a 2.4 feature.
>> or even on that optimization staying in CPython.
> You also shouldn't count on dicts being O(1) on lookup, or "i in
> myDict" being faster than "i in myList".
Python dictionaries (and most decent hash table implementations) may not
be O(1) technically, but they are expected O(1) and perform O(1) in
practice (at least for the Python implementations). If you have
particular inputs that force Python dictionaries to perform poorly (or
as slow as 'i in lst' for large dictionaries and lists), then you should
post a bug report in the sourceforge tracker.
More information about the Python-list