How to list objects on separate lines? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to list objects on separate lines? (/thread-6969.html) |
How to list objects on separate lines? - Intelligent_Agent0 - Dec-16-2017 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? RE: How to list objects on separate lines? - mpd - Dec-16-2017 https://docs.python.org/3/tutorial/index.html There's a section on lists. RE: How to list objects on separate lines? - snippsat - Dec-16-2017 >>> 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 RE: How to list objects on separate lines? - Intelligent_Agent0 - Jan-10-2018 Thanks a lot, works perfect. |