Python Forum

Full Version: How to list objects on separate lines?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


Hello community,the issue seems simple but I just can't figure it out, so I'm going to get right to it. I saw it on the web before, there's a function to make each object in a list be printed out on a separate line. Like, if i ha a list "L" with objects "orange","blue" and "red", it could be delivered like this:

[python]

>>> Orange
blue
Red


Does any body know the code to make a list "print" out like this?
>>> lst = ['Orange', 'Blue', 'Red']
>>> lst
['Orange', 'Blue', 'Red']
>>> # A loop work
>>> for item in lst:
...     print(item)
...     
Orange
Blue
Red

>>> # join a new line work
>>> '\n'.join(lst)
'Orange\nBlue\nRed'
>>> # print will show new line
>>> print('\n'.join(lst))
Orange
Blue
Red
Thanks a lot, works perfect.