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
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'
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,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.