I have a project wherein I have to get the follow-up elements of elements in on_time.
For example:
j_set = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
s_follow_int = [[2, 3], 4, [5, 6], [6, 8], [7, 8], 9, 8, 10, 10, 11]
on_time = [4, 5]
The code I have looks like this:
# element in on_time except 1, get follow_finish_act
follow_finish_act = []
for a, d in zip(j_set, s_follow_int):
if a in on_time and a != 1:
if len(on_time) > 1:
follow_finish_act.append(d)
else:
follow_finish_act = d
Output I am getting:
follow_finish_act = [[6, 8], [7, 8]]
Expected Output:
follow_finish_act = [6, 7, 8]
I am having trouble when length of on_time is more than 1. I think the problem is flattening the irregular lists (can be nested and integer) without duplicates. Since, I cannot get my expected output.
Any help/suggestions would be appreciated! Thank you!
Edit: Code I used for trying to flatten output of follow_finish_act
def flatten(lss):
for item in lss:
try:
yield from flatten(item)
except TypeError:
yield item