Printing each item of a list on a separate line?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PatrickG

    #1

    Printing each item of a list on a separate line?

    Hi! I'm trying to print a list that contains names and when it prints the items in the list all print on the same line. What I want is for each name to print on its own line.

    For example this is what I get:

    Smith, John Reilly, James Sykes, Matt

    What I want is this:

    Smith, John
    Reilly, James
    Sykes, Matt

    The names come from user input by the way.

    This is my code to print the list:
    Code:
    visitors.sort()
    print ' '.join(visitors)
    Last edited by bvdet; Nov 1 '10, 01:49 AM. Reason: Add code tags. Please use code tags when posting code. [code]....code goes here....[/code]
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Look up traversing a list.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Or you can use:
      Code:
      print "\n".join(visitors)

      Comment

      Working...