mercredi 25 janvier 2023

How create Google Colab checkboxes based on the elements in a list?

I am trying to create checkboxes in Google Collab, and I know that I can use the following code to create a single checkbox:

boolean_checkbox = False #@param {type: "boolean"}

However, I want to create multiple checkboxes based on the elements in a list. I have tried using a for loop and the exec() function to create new variables for each element in the list, like this:

my_list = ["a","b","c","d"]
for i in my_list:
    exec(i+" = True #@param {type: 'boolean'}")

However, this doesn't seem to work. Is there a way to use the exec() function or another method to create multiple checkboxes based on the elements in a list in Google Collab?

I am expecting to see the checkboxes in the form section of the Google Collab notebook, for example:

a ☐
b ☑︎
c ☑︎
d ☐

That the above list of elements is just an example, items will be replaceable.




Aucun commentaire:

Enregistrer un commentaire