Time travel - how to simplify?

Ben Finney ben+python at benfinney.id.au
Tue Nov 14 16:43:01 EST 2017


Ben Finney <ben+python at benfinney.id.au> writes:

>     import itertools
>
>     month_values = sorted(list(fut_suffix.keys()))
>     month_cycle = itertools.cycle(month_values)
>
>     month_choice = 7
>     three_months_starting_at_choice = []
>     while len(three_months_starting_at_choice) < 3:
>         this_month = next(month_cycle)
>         if this_month >= month_choice:
>             three_months_starting_at_choice.append(this_month)

Sorry, I now realise that won't do what you want; the wrap around from
12 to 1 will cause ‘this_month >= month_choice’ to be false.

Well, I won't correct it; maybe this is a useful exercise. Do you have a
way to fix that so it will work?

-- 
 \      “I am too firm in my consciousness of the marvelous to be ever |
  `\       fascinated by the mere supernatural …” —Joseph Conrad, _The |
_o__)                                                     Shadow-Line_ |
Ben Finney




More information about the Python-list mailing list