On Tuesday, November 14, 2017 at 1:44:17 PM UTC-6, Ben Finney wrote:
> Andrew Z <form...@gmail.com> writes:
> 
> > Now i want to get certain number of months. Say, i need  3 months duration
> > starting from any month in dict.
> >
> > so if i start @ 7th:
> > my_choice =7
> >  for mnth, value in fut_suffix:
> >     if my_choice >= mnth
> >        # life is great
> > but if :
> > my_choice = 12 then my "time travel" becomes pain in the neck..
> 
> The ‘itertools’ library in the Python standard library
> <URL:https://docs.python.org/3/library/itertools.html> has what you
> need:
> 
>     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)

Ben's advice is spot on[1], and exactly what i would do, but
i believe it's important for you to discover how to
implement a simple cycling algorithm yourself, _before_
reaching for the pre-packaged junkfood in the itertools
module. Can you do it? If not, then do as much as you can
and then ask for help. Hey, you're only hurting yourself if
you don't learn how. And it's surprisingly easy!

[1] and it looks as though he included the kitchen sink,
washcloths, dish soap, and some fine china as well! ಠ_ಠ
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to