Skip to content

Instantly share code, notes, and snippets.

@RaD
Created July 12, 2011 11:01
Show Gist options
  • Save RaD/1077773 to your computer and use it in GitHub Desktop.
Save RaD/1077773 to your computer and use it in GitHub Desktop.
This iterator generates the names of week day starting from `start` day.
def weekday_iterator(start=0):
""" This iterator generates the names
of week day starting from `start` day. """
names = ('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su',)
maximum = len(names)
i = 0
while i < maximum:
index = (start + i) % maximum
value = names[index]
i += 1
yield (index, value)
@RaD
Copy link
Author

RaD commented Jul 12, 2011

Usage:

>>> for i in weekday_iterator(): print i,
... 
mo tu we th fr sa su
>>> for i in weekday_iterator(2): print i,
... 
we th fr sa su mo tu
>>> for i in weekday_iterator(10): print i,
... 
th fr sa su mo tu we
>>> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment