Python-Returning to a specific point in the code
Question: So I'm writing a little bit of code as a fun project that will randomly
generate a subject for me to study each day. But once a subject has appeared
once I don't want it to appear for the rest of the week. To do this I'm using
a list. Basically, when it picks the subject it adds it to the list and the
next time it checks to see if it's already on the list, and if so, I want it
to return to the random number generator. How do I do this? Here's my code.

    
    
    import random
    import time
    import datetime
    
    #Subject veto list
    x=[]
    
    # Messages to instil, um, enthusiasm.
    if datetime.date.today().strftime("%A") == "Monday":
        response = input("Here we go again. Are you ready? ")
    elif datetime.date.today().strftime("%A") == "Tuesday" or "Wednesday" or "Thursday":
        response = input("Are you ready? ")
    elif datetime.date.today().strftime("%A") == "Friday":
        response = input("Half day! Are you ready? ")
    elif datetime.date.today().strftime("%A") == "Saturday" or "Sunday":
        response = input("It's the weekend! Are you ready? ")
    
    # Random picking of subject to study. Also adds sbject to veto list for rest of week.
    if response == "Yes":
            subject = random.randint(1, 7)
            print("Today you are studying...")
            time.sleep(3)
            if subject == (1):
                "Englsh" in x
                print("English")
                x.extend([English])
            elif subject == (2):
                "Irish" in x
                print("Irish")
                x.extend([Irish])
            elif subject == (3):
                "Maths" in x
                print("Maths")
                x.extend([Maths])
            elif subject == (4):
                "French" in x
                print("French")
                x.extend([French])
            elif subject == (5):
                "Physics" in x
                print("Physics")
                x.extend([Physics])
            elif subject == (6):
                "Chemistry" in x
                print("Chemistry")
                x.extend([Chemistry])
            elif subject == (7):
                "History" in x
                print("History")
                x.extend([History])
    


Answer: This function will let you choose a random thing from a list based on the
weekday, without repeating* and without having to store anything between runs.
The only potential issue would be if Python's PRNG was changed mid-week :P.

    
    
    import datetime
    import itertools
    import random
    
    def random_choice_per_date(iterable, date=None):
        choices = list(itertools.islice(iterable, 7))
        date = date or datetime.date.today()
    
        year, week, weekday = date.isocalendar()
    
        rand = random.Random((year, week))  # Seed PRNG with (year, week)
        rand.shuffle(choices)
    
        index = weekday % len(choices)
    
        return choices[index]
    

This is generalizable beyond dates, but I didn't want to complicate the code.

* _It**will** repeat if the iterable has less than seven items. It also only uses the first seven items at most._

