Python List output as Markdown Lists - Beautify Lists

Hi guys,

I am a beginner both in Python and Streamlit. I have a list of strings that I want to show, but by default st.write() function outputs them as following.

image

But I want to show something like this.

image

Does anybody have any idea how I can do this? Any help is appreciated.

Hey @bimgeek

Welcome to the Streamlit Community :tada::tada:

This can be done using -

lst = ['a', 'b', 'c']

for i in lst:
    st.markdown("- " + I)

Best,
Kanak

1 Like

Hey @Kanak,

Thanks for answering. Even though, it creates a markdown, there is a space between two values. I think it is because we are calling markdown every time there is an item. See the difference of two lists below👇. Do you have any recommendation to achieve a list like in the image below?
image
image

I tried it with this code and it did the trick -

lst = ['a', 'b', 'c']

s = ''

for i in lst:
    s += "- " + i + "\n"

st.markdown(s)
1 Like

thanks man. this did the trick.