[Baypiggies] len(iterable)

Drew Perttula drewp at bigasterisk.com
Thu Aug 7 04:29:46 CEST 2008


Shannon -jj Behrens wrote:
> def test_iter_len():
>     assert_equal(iter_len(xrange(5)), 5)
> 
> 
> Gees, I'm so boring sometimes!
> 

BTW, did you ever notice that the result of xrange has a __len__ already?

len(xrange(5)) -> 5

Maybe your iter_len should try that first, in case the incoming object 
has thoughtfully provided a __len__ method.



More information about the Baypiggies mailing list