python在列表列表之间的电子邮件正文中添加空格

时间:2018-01-31 09:52:02

标签: python list email

假设我有以下列表:

ListofLists = [2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13] 

我想将列表列表添加到电子邮件正文中,如下所示:

body = "Here are the informations" + ListofLists 

我想将两个列表分开,并将每个列表打印成一个单独的行,所以它看起来像一张桌子,我怎么能这样做?

我想要的输出如下:

Number 1  Number 2  Number 3  Number 4  Number 5  
   2         3         4         5         6
   8         9        10        11        11

2 个答案:

答案 0 :(得分:0)

这就是你的意思:

listOfLists = [2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13]

body = ("here are the informations")

for a in listOfLists:
    print(body + str(a))

输出如下:

here are the informations[2, 3, 4, 5, 6, 7]
here are the informations[8, 9, 10, 11, 12, 13]

答案 1 :(得分:0)

此代码:

listOfLists = [[2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13]]
for i in range(len(listOfLists[0])):
    print('Number',(i+1), end = "  ")
for i in range(len(listOfLists)):
    print()
    for j in listOfLists[i]:
        print('  ',j, end = (7-len(str(j+1)))*' ')

输出如下:

Number 1  Number 2  Number 3  Number 4  Number 5  Number 6  
   2         3         4         5         6         7      
   8         9        10        11        12        13