<div dir="ltr"><br><div class="gmail_quote">On Fri, Aug 29, 2008 at 7:17 PM, Steven Bethard <span dir="ltr"><<a href="mailto:steven.bethard@gmail.com">steven.bethard@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Fri, Aug 29, 2008 at 6:25 PM, Bruce Leban <<a href="mailto:bruce@leapyear.org">bruce@leapyear.org</a>> wrote:<br>
> Not quite: len(items) requires iterating across the entire list which may<br>
> not be necessary or desirable. Plus you may need an intermediate variable to<br>
> store it. I think that's inferior.<br>
<br>
</div></div>If len(items) requires iterating across the entire list, then you're<br>
not using a Python list object, you're using someone else's (poorly<br>
implemented) list data structure. Python lists give len(obj) in O(1).<br>
</blockquote><div><br>items need not be a literal list. If you can compute this<br>   len([t for t in range(100) if foo(t)]):<br>without iterating over the list, then there's a Turing award waiting for you. :-) (Yes, if you know what foo is perhaps you can optimize that. I'm not counting that.) This is also why you may need an intermediate variable: you don't want to compute that list more than once because foo(t) may have a side effect.<br>
    <br>--- Bruce<br></div></div></div>