I am using plotly-dash dropdown menu with multiple selection enabled. so the dropdown menu returned either an empty list when no selection, or a string ( with one selection) or list of strings ( with multiple selection).
How do I check if returned is not empty?
if I use below, it doesn’t work for empty list
JavaScript
x
3
1
if selection is not None:
2
3
Thanks for your help.
Advertisement
Answer
I think this should work:
JavaScript
1
9
1
def check_selection(selection):
2
if selection:
3
if isinstance(selection, list):
4
return "Multiple Selections"
5
else:
6
return "One Selection"
7
else:
8
return "No Selection"
9
Empty sequences (like strings and lists) are considered “falsy” in Python, and evaluate to the boolean False
. Please let me know if I interpreted your question correctly, and this answer helps.