mercredi 17 juin 2020

How to read all elements in a list at the same time using if statement?

I have a project that goes like this:

e_list = [[], [1], [1], [2], [3], [3], [5], [4, 7], [6], [8, 9], [10]]
s_follow_int = [[2, 3], 4, [5, 6], 8, 7, 9, 8, 10, 10, 11]

precedence = e_list[follow_finish_act - 1]
if len(precedence) > 1:
    if precedence in finish_act:
        q_active.append(follow_finish_act)
    else:
        q_active = q_active
else:
    q_active.append(follow_finish_act)

The objective is before adding the follow_finish_act or follow-up activity of a finish activity, its precedence must be checked first. If all precedence are in finish_act, then follow_finish_act can be added to q_active. If not, q_active remains.

The problem with the code above is if I have:

 finish_act = [4]
 follow_finish_act = 8 # from s_follow_int
 precedence of follow_finish_act = [4, 7] # from e_list

Since, Activity 7 is still not in finish_act, then follow_finish_act 8 cannot be added to q_active. The thing is, with the code above, even if 7 is already in finish_act alongside 4, it still won't add 8 to q_active. I tried changing it to if all(precedence) in finish_act, but it automatically adds 8 even if 7 is still not finish.

Expected output if 7 is not finished:

q_active = []

If both 4 and 7 are in finish_act, then, expected output is:

q_active = [8]

What changes should I make for the If precedence... to get what I wanted?

Any help/suggestion would be appreciated! Thank you!

Aucun commentaire:

Enregistrer un commentaire