Python object that allows you to access next() and prev() items from a list.
Why Cylon? Well it was either that or KITT and Cylon just sounded cooler! For those of you not old enough, both Cylons and KITT had a light that moved left to right, just like you can access the items in this object.
Normal list() operations are supported as well.
Clone the project to your computer. Assuming you have a Projects folder:
cd Projects
git clone https://github.com/clamytoe/Cylon.git
cd Cylon
python setup.py install
After it has been installed, just use it like any other module. One thing to note is to make sure not to forget to import prev as well. It's not perfect, but until I can figure out how to do it without it, it'll have to be like this:
>>> from cylon import Cylon, prev
>>> models = [
... 'U-87 Cyber Combat Unit',
... 'Civilian Cylon',
... 'Cylon War-Era Centurion',
... 'Cython',
... 'Djerba Centurion',
... 'Modern Centurion',
... 'Inorganic Humanoids',
... 'Cylon Spacecraft',
... 'Cylon Hybrids',
... 'Humanoid Cylons',
...]
>>> cylon_models = Cylon(models)
>>> cylon_models.current()
'U-87 Cyber Combat Unit'
You can also print the current item by simply printing the object:
>>> print(cylon_models)
U-87 Cyber Combat Unit
>>> cylon_models.next()
'Civilian Cylon'
To move to the next one:
>>> next(cylon_models)
'Civilian Cylon'
Now if you check the current item:
>>> cylon_models.current()
'Civilian Cylon'
This one works the same way:
>>> cylon_models.current()
'Civilian Cylon'
>>> cylon_models.prev()
'U-87 Cyber Combat Unit'
>>> prev(cylon_models)
'U-87 Cyber Combat Unit'
>>> cylon_models.current()
'U-87 Cyber Combat Unit'
If you happen to go past the beginning or end of the list, it simply wraps around:
>>> prev(cylon_models)
'Humanoid Cylons'
I was recently made aware that in the world of High Performance Computing (HPC) the concept of neighbors is called a "stencil". So that's what I called it. By default it will show the two items before and after the currently selected item.
>>> cylon_models.stencil()
['Cylon Spacecraft', 'Cylon Hybrids', 'Humanoid Cylons', 'U-87 Cyber Combat Unit', 'Civilian Cylon']
You can also specify more neighbors as well:
>>> cylon_models.stencil(7)
['Cylon War-Era Centurion', 'Cython', 'Djerba Centurion', 'Modern Centurion', 'Inorganic Humanoids', 'Cylon Spacecraft', 'Cylon Hybrids', 'Humanoid Cylons', 'U-87 Cyber Combat Unit', 'Civilian Cylon', 'Cylon War-Era Centurion', 'Cython', 'Djerba Centurion', 'Modern Centurion', 'Inorganic Humanoids']
Here's a snippet of what's available:
Help on class Cylon in module cylon.cylon:
class Cylon(collections.abc.MutableSequence)
| Provides next() and prev() methods to a list object
|
| If you need to traverse your list object in either direction,
| then this is the module to use.
|
| Methods defined here:
|
| __delitem__(self, index)
| Remove the item at the index indicated
|
| __getitem__(self, index)
| Return the item at the index indicated
|
| __init__(self, items=[])
| Initialize object with the list of items that are passed to it
|
| __len__(self)
| Return the length of the object
|
| __next__(self)
| Return the next item in the object
|
| __prev__(self)
| Return the previous item in the object
|
| __repr__(self)
| Return repr(self).
|
| __setitem__(self, index, value)
| Set the value of the object at the specified index
|
| __str__(self)
| Return currently selected item
|
| current(self)
| Return the current item
|
| insert(self, index, value)
| Insert value/object at the given index
|
| next(self)
| Display the next item without changing current
|
| prev(self)
| Display the previous item without changing current
|
| stencil(self, count=2)
| Return a list with before and after neighbors of current item
|
| Count determines how many of each are displayed.
|