Pythonic way to print list items

myList = [1, 2, 3, 4]

in python 2.x:
print(" ".join(map(str, myList)))
1 2 3 4
or
print " ".join([str(x) for x in myList] )
1 2 3 4

in python 3.x:
print(*myList, sep=' ')
1 2 3 4
#You can get the same behavior on Python 2.x using from __future__ import print_function

 

posted @ 2016-09-17 16:20  ohword  阅读(188)  评论(0)    收藏  举报