1

I am trying for a roaster method, where I have want to loop over the same list and print primary,secondary and change the primary and secondary every week,if weekday is monday.

team = [('abc', 123),('def', 343),('ghi', 345),('jkl', 453)]

Week 1:- primary :- ('abc', 123) secondary :- ('def', 343)

Week 2:- primary:- ('ghi', 345) secondary:- ('jkl', 453)

Week 3:- primary:- ('jkl', 453) secondary:-('abc', 123)

And so on.

team = [('abc', 123),('def', 343),('ghi', 345),('jkl', 453)]
count = 0
if week_day == 'Wed':
    if True:
        count += 1
print('count', count)
print('pri', team[count][0])
print('sec_name', team[count + 1])
1
  • 1
    you need a cron job. Commented Aug 7, 2019 at 11:58

1 Answer 1

1

In Python 3 you can use generators/. With itertools.cycle you can iterate over a list indefinitely:

import itertools as it

team = [('abc', 123), ('def', 343), ('ghi', 345), ('jkl', 453)]

pri_gen = it.cycle(team)
sec_gen = it.cycle(team)
next(sec_gen) # remove the first abc and start with def

for pri, sec in zip(pri_gen, sec_gen):
    print(pri, sec)
    # wait until next monday
Sign up to request clarification or add additional context in comments.

2 Comments

For loop is continuously printing the pri,sec.I need only one for the week and next week the second one
@vinaykn then you'll have to use a database or some other way to store the state. Your program probably won't run indefinitely with one week sleep.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.