Skip to content
Advertisement

How to let if fuction output only one output in python?

I am trying to use if function to classify the items into 3 categories in python. My code is as follows.

JavaScript

However, there are 25 outputs which is out of the range of 14 (the number of items in WBS4_ELEMENT_list_0 ). Please help me to keep if fuction output only one output in python.

Advertisement

Answer

You can do it in a cleaner and faster way by using list comprehensions and a dict:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement