본문 바로가기
Other/For You

if statement making list with for loop

by wisejlog 2022. 10. 25.

two uses

[key for key in data.keys() if data[key]['column_A'] is not None]

In this case we don't need to specify else and the logic only make output with keys with True value.

 

[key if data[key]['column_A'] is not None else 'value_B' for key in data.keys()]

In this case you need to specify else statement or you got some error. 

-> you need to delete value_B if you don't need the value