Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
/ viewtools Public archive

"view" objects which can be manipulated with slices without introducing copies

License

Notifications You must be signed in to change notification settings

afq984/viewtools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

viewtools

Viewtools provides "view" objects which can be manipulated with slices without introducing copies.

SequenceView

>>> import viewtools
>>> view = viewtools.SequenceView([2, 1, 4, 7, 4, 8, 3, 6, 4, 7])
>>> view
SequenceView([2, 1, 4, 7, 4, 8, ...])[0:10:1]

The usual sequence methods works on views:

>>> view[3::2]
SequenceView([2, 1, 4, 7, 4, 8, ...])[3:10:2]
>>> list(view[3::2])
[7, 8, 6, 7]
>>> view[3::2][1]
8
>>> 6 in view[3::2]
True
>>> view[3::2].count(7)
2
>>> view[3::2].index(8)
1
>>> view[3::2].index(3)
ValueError: 3 is not in view

Slicing a view doesn't copy the underlying sequence unless requested:

>>> view[3::2][::-1]
SequenceView([2, 1, 4, 7, 4, 8, ...])[9:1:-2]
>>> list(view[3::2][::-1])
[7, 6, 8, 7]

Planning

  • StringView which supports the usual string methods
  • ZipView

About

"view" objects which can be manipulated with slices without introducing copies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages