for s in strategies:
strats_having_fcs = {a.strategy: a.algorithmType for a in s.algorithms if a.algorithmType == AlgorithmTypeEnum.feedback_control.value}
can we make it in single line by comprehension?
for s in strategies:
strats_having_fcs = {a.strategy: a.algorithmType for a in s.algorithms if a.algorithmType == AlgorithmTypeEnum.feedback_control.value}
can we make it in single line by comprehension?
Just:
strats_having_fcs = {a.strategy: a.algorithmType for s in strategies for a in s.algorithms if a.algorithmType == AlgorithmTypeEnum.feedback_control.value}
Have a look at this SO question about within-list comprehension. For me this clarified a lot how the logic behind this works.
IIUC, perhaps you are looking for this nested comprehension
strats_having_fcs = {a.strategy: a.algorithmType for s in strategies for a in s.algorithms
if a.algorithmType == AlgorithmTypeEnum.feedback_control.value}