[go: up one dir, main page]

Skip to content
/ Cylon Public

Python object that allows you to access the next and previous items from a list.

License

Notifications You must be signed in to change notification settings

clamytoe/Cylon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cylon

Python object that allows you to access next() and prev() items from a list.

Python version Build Status BCH compliance GitHub issues GitHub forks GitHub Stars License

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.

How to set it all up

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

How to use

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)

Accessing current item

>>> 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

Accessing next item

>>> 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'

Accessing prev item

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'

Accessing nearby neighbors

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']

For further features review help()

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.
 |

About

Python object that allows you to access the next and previous items from a list.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages