Message248474
Hi, and sorry David, but I think you haven’t understood what I was proposing.
Maybe that was too much text and detail to read at once, while skipping the relevant details:
Python has iterators and iterables. iterators are non-reentrant iterables: once they are exhausted, they are useless.
But there are also iterables that create new, iterators whenever iter(iterable) is called (e.g. implicitly in a for loop). They are reentrant. This is why you can loop sequences such as lists more than once.
———————————————————————
One of those reentrant iterables is range(), whose __iter__ functions creates new lazy iterables, which has a __len__, and so on. It even has random access just like a sequence.
Now it’s always entirely possible to *lazily* determine len(chain(range(200), [1,2,5])), which is of course len(range(200)) + len([1,2,5]) = 200 + 3 = 203. No reentrant iterables are necessary here, only iterables with a __len__. (Simply calling len() on them all is sufficient, as it could only create a TypeError which would propagate upwards)
———————————————————————
To reiterate:
1. Lazy doesn’t mean non-reentrant, just like range() demonstrates.
2. I didn’t propose that this works on arbitrary iterables, only that it works if you supply iterables with suitable properties (and throws ValueError otherwise, just like len(some_generator_function()) already does)
3. I know what I’m doing, please trust me and read my proposal carefully ;) |
|
Date |
User |
Action |
Args |
2015-08-12 21:23:26 | flying sheep | set | recipients:
+ flying sheep, steven.daprano, r.david.murray |
2015-08-12 21:23:26 | flying sheep | set | messageid: <1439414606.92.0.637422862697.issue24849@psf.upfronthosting.co.za> |
2015-08-12 21:23:26 | flying sheep | link | issue24849 messages |
2015-08-12 21:23:26 | flying sheep | create | |
|