jeudi 28 juin 2018

list comprehension looping with if/else statement from 2d nested dictionary working with pulp

another pointer needed.

the following snippet works and it produces exactly what I want, however
i need soms pointers on how to be more pythonic with the line "if avail[employee, day, "Morning"].varValue==0 and
avail[employee, day, "Mid"].varValue==0 and avail[employee, day, "Night"].varValue==0:"

Shift_pattern_Master = ["Morning", "Mid", "Night"]

for employee in Employees:
    for day in Days:
        if avail[employee, day, "Morning"].varValue==0 and    
            avail[employee, day, "Mid"].varValue==0 and 
            avail[employee, day, "Night"].varValue==0:
                print (f"{employee} on {day} is off.")
        else:
            for shift in Shift_pattern_Master:
                if avail[employee, day, shift].varValue==1:
                    print (f"{employee} on {day} works in {shift}.") 

so I tried "if avail[employee, day, shift].varValue==0 for shift in Shift_pattern_Master:" to make it a generic condition and it keeps saying "for" is INVALID SYNTAX.

i think i am missing something, but i don't know what. thanks for any help in advance.

Aucun commentaire:

Enregistrer un commentaire