Azimout's Linux weblog

print python list vertically

with 3 comments

A one-liner to vertically print all items in a Python list:

print "\n".join(str(x) for x in mylist)


Written by azimout

06/04/2011 at 14:41

Posted in Tricks

3 Responses

Subscribe to comments with RSS.

  1. Run it through a for loop and print it, best way to vertically print the list.

    for item in list:
    print item

    As simple as that!

    Arvind Muralidharan

    02/08/2011 at 19:55

    • It’s the simplest way, true. I just don’t like for loops and try to avoid them when I can through list comprehensions, etc

      It’s good that you clarified that, though. Thanks!


      03/08/2011 at 07:27

      • your original one-line includes a for loop “for x in mylist”.


        22/04/2014 at 14:49

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: