dict comprehension python if else code example
Example 1: if else in dictionary comprehension python
{ (some_key if condition else default_key):(something_if_true if condition
else something_if_false) for key, value in dict_.items() }
Example 2: dict comprehension python
keys=['var1','var2','var3']
my_dict={key:np.zeros(10) for key in keys}