1

Is there a pythonic way to add a key to a dictionary if the condition is True, and just completely ignore it (skip) if it is false?

dict = {}

frame = scatter[x > y]
if frame.empty == False:
    dict[pct] = frame
else:
    None

I've tried writing:

dict[pct] = frame if frame.empty == False else None

But the problem here is that the "else None" adds a "None" value to the dictionary , and I need it to completely ignore/skip (not do anything) if else is activated.

thomas.mac
  • 1,236
  • 3
  • 17
  • 37

0 Answers0