ValueError vs IndexError, unpacking arguments with string.split

Morten W. Petersen morphex at gmail.com
Sun Dec 2 13:35:20 EST 2018


On Sun, Dec 2, 2018 at 1:20 PM Chris Angelico <rosuav at gmail.com> wrote:

> On Sun, Dec 2, 2018 at 11:08 PM Morten W. Petersen <morphex at gmail.com>
> wrote:
> >
> > On Sun, Dec 2, 2018 at 12:49 PM Chris Angelico <rosuav at gmail.com> wrote:
> >> To my knowledge, len(x) == len(list(x)) for any core data type that
> >> has a length.
> >
> > >>> len(range(0,100,3))
> > 34
> > >>> range(0,100,3).__len__
> > <method-wrapper '__len__' of range object at 0x7f144d5e3210>
> > >>> range(0,100,3).__len__()
> > 34
> > >>>
> >
> > But again, I guess an integer-to-be-calculated would be suitable
> > for iterators where it is very expensive to do a list or other
> > similar calculation.
> >
> > These operations take quite a bit of time:
> >
> > >>> x=list(range(0,100000000,3))
> > >>> y=len(list(range(0,100000000,3)))
> > >>>
> >
>
> Of course they take a lot of time - you're asking for the generation
> of some thirty-three million integer objects, each one individually
> built and refcounted (in CPython), just so you can count them. But my
> point about the equivalency is that, rather than calculating
> len(list(range(...))), you can calculate len(range(...)), and you can
> be confident that you WILL get the same result.
>


Mm, yes, I was aware that it took up references, one more zero
and it would dump a MemoryError.

I hacked a bit of code today, got get my head around the concept
of integer-of-unknown-size, and ended up with this so far:

https://github.com/morphex/misc/blob/98e44915ffeb1cc3ec3050135ea503eb901c01e2/iterator.py

I guess there could be of some (contrived?) use to have an iterator that
will
take different fractions, which will stop iterating over digits once a
repeating
pattern has been found.

Anyway, the more I meddled with the idea of an integer-of-unknown-size,
the more I think that it isn't necessary with the right use of other
concepts
and abstractions.

It could however be a smaller part of a nice, clean pattern/concept.

-Morten


-- 
Videos at https://www.youtube.com/user/TheBlogologue
Twittering at http://twitter.com/blogologue
Blogging at http://blogologue.com
Playing music at https://soundcloud.com/morten-w-petersen
Also playing music and podcasting here:
http://www.mixcloud.com/morten-w-petersen/
On Google+ here https://plus.google.com/107781930037068750156
On Instagram at https://instagram.com/morphexx/



More information about the Python-list mailing list