1

I have a list

    l1 = ['a','b','c','d','e']  

When I run print l1 it returns:

    ['a','b','c','d','e']

When I try

    for a in l1
        print ' '.join(map(str,a))

I get

    a  
    b  
    c  
    d  
    e  

What I want to get though is

    a b c d e
Mrahta
  • 85
  • 6

2 Answers2

7

What join is doing is it returns a string, which is the concatenation of the strings in the sequence (in your case l1). The separator between elements is the string providing this method.

>>> l1 = ['a','b','c','d','e']
>>> ' '.join(l1)
'a b c d e'
Vor
  • 33,215
  • 43
  • 135
  • 193
1

In Python 2.7, you can also add a comma after the print statement, to cause the next one to print on the same line.

for a in l1:
    print a,
Jonathan Clede
  • 126
  • 1
  • 5