Clearing all selected items (check box, radio buttons & selectbox)

Inspired by This answer I’ve written the following code that work for the checkbox as well:

import streamlit as st

# create a function that sets the value in state back to an empty list
def clear_all():
    for i in selections:
        st.session_state[f'checkbox{i}'] = False
    return

st.title("Clear multiselect with stateful button")

selections = ["a","b","c","d"]

for i in selections:
    st.checkbox(i, value=False, key=f'checkbox{i}')

# check state
st.session_state

#create your button to clear the state of the checkboxes
st.button("Clear all", on_click=clear_all)