FWIW, here's something for working with memory-efficient sequences (and generators), which should get more features in the future:

pip install git+https://github.com/k7hoven/views

Some examples of what it does:

py> from views import seq
py> seq[::range(3), None, ::"abc", "Hi!"]
<sequence view 8: [0, 1, 2, None, 'a', 'b', 'c', 'Hi!'] >
py> seq[::range(100)]
<sequence view 100: [0, 1, 2, 3, 4, ..., 96, 97, 98, 99] >

py> from views import seq, gen
py> seq.chain([1, 2, 3], [4, 5, 6])
<sequence view 6: [1, 2, 3, 4, 5, 6] >
py> list(gen.chain([1, 2, 3], [4, 5, 6]))
[1, 2, 3, 4, 5, 6]

py> from views import range
py> range(5)
range(0, ..., 4)
py> range(1, 10, 3)
range(1, ..., 7, step=3)
py> range(1, ..., 5)
range(1, ..., 5)
py> range(1, 3, ..., 10)
range(1, ..., 9, step=2)

Sequences are perhaps more interesting than the generators, which are just there, because I don't want to implicitly try to convert generators/iterators into sequences. I do intend to add at least one *explicit* mechanism.

Much of this is thread-safe, but the assumption in general is that one does not modify the original sequences. One problem is that there's no way to efficiently check if the originals have been mutated. Currently it just sometimes checks that the lengths match. 

This approach can also be a big performance boost because it avoids copying stuff around in memory etc. However, many possible optimizations have not been implemented yet, so there's overhead that can be significant for small sequences. For instance, itertools could be used to optimize some features.

––Koos



On Tue, Nov 21, 2017 at 2:35 PM, Serhiy Storchaka <storchaka@gmail.com> wrote:
21.11.17 13:53, Kirill Balunov пише:
If I can not copy at Python level, I can 'tee' when 'star_pos' is reached.

And tee() uses a real RAM for saving items.


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--
+ Koos Zevenhoven + http://twitter.com/k7hoven +