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)
4 Likes

thanks man. this did the trick.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.