Ipywidgets list - remove widgets from list

Viewed 69

I want to remove an ipywidget from a list of ipywidgets but the following error is given:

"ValueError: list.remove(x): x not in list"

Code:

import ipywidgets as widgets

result = []

result.append(widgets.SelectMultiple(description="Widget"))

result.remove(widgets.SelectMultiple(description='Widget', options=(), value=()))
2 Answers

I just used an #ordereddictionary and it worked with the del function.

The reason for your error is that you were creating a new widget instance, and trying to remove it. Even though the widgets are created equal, they are not the same object. There is a subtle difference in python between equality and identity.

Try the code below instead, which refers to the widget by identity.

import ipywidgets as widgets

result = []

w = widgets.SelectMultiple(description="Widget")

result.append(w)

result.remove(w)
Related