mercredi 21 juillet 2021

Trying to check if a name is in a list then continue

This is a sample of code that I am using to distribute holiday shifts randomly between employees.

I would like to be able to enter the previous years holiday for each employee. Then if the holiday chosen randomly matches a previous holiday it skips that employee and moves to the next.

import random
import sys
from itertools import cycle, product

print ('start','\n')
nyd = ['zia', 'bettina'] 
holiday_list = ['NYD','MLK','PRD','MEM','IND','LAB','THD','XMS']
shift_list = ['Night', 'Noon']
emp_list = ['Donna', 'Gessica', 'Bettina', 'Irina', 'Zia', 'Marsha',]


assigments = []
holiday_shifts = product(holiday_list, shift_list) # combine all the holidays and shifts via product()
random.shuffle(emp_list) # randomize our employees
for emp in cycle(emp_list):
    try:
        assigment = list(next(holiday_shifts)) + [emp]
        assigments.append(assigment)
    except StopIteration:
        # we've assigned all the holiday_shifts
        break
def schedule():
    for a in assigments:
        print(",    ".join(a))
schedule()

# y = input("enter no whose table you want: ")


# for x in range(sys.maxsize**10):
#     schedule()
print ('\n','next','\n')

print ("          end              ")



Aucun commentaire:

Enregistrer un commentaire