Taking a list as input from a user

hello, please how will I make a user input a list ?

1 Like

Hi @emmanuel_akpe. Welcome to the Streamlit community! :slight_smile:

Can you please provide a bit more context? Are you looking to have the user input a list of string values? Are the values drawn from a finite set (such as with a select box), or are they arbitrary, such as with a text input?



Thanks for the reply
I want the user to input a list of integer values

Are the values arbitrary or from some range?

They are arbitrary please

Hi @emmanuel_akpe,

I think you have two options here,

  1. If you have a defined set of integers just use multiselect and it should serve the purpose.
  2. If the user can enter some random numbers you can use regex with text input,
import streamlit as st
import re

collect_numbers = lambda x : [int(i) for i in re.split("[^0-9]", x) if i != ""]

numbers = st.text_input("PLease enter numbers")

fixed_numbers = st.multiselect("Please select numbers", [1, 2, 3, 4, 5])

The regex code above splits on anything non integers so if the user inputs something like 1,abcd2efg3 it will give you a list of [1, 2, 3]

Hope it helps ! :slight_smile:

1 Like