2014-12-05 102 views

回答

3

是相反的,我认为正确的方法将是这样的:

>>> print "\n".join(["%s  %s" % t for t in zip(x,y)]) 
1.2  10 
2.2  8.999 
3  6 
4  4 
5  1 
>>> 
+0

打我2秒:) – 2014-12-05 05:47:00

+0

@ToClickorNottoClick可能是因为我先看到这个问题,我投票给你。 – 2014-12-05 05:48:11

+0

@ToClickorNottoClick只需一个注释,在您的答案中使用格式字符串,而不是'+'。 – 2014-12-05 05:50:08

2

这是自己所想的?

string = "".join(["{}\t{}\n".format(str(x), str(y)) for x, y in zip(a, b)]) 
print string #Converts to pretty format 

>>> a=[1.2,2.2,3,4,5] 
>>> b=[10,8.999,6,4,1] 
>>> string = "".join([str(x)+'\t'+str(y)+'\n' for x, y in zip(a, b)]) 
>>> print string 
1.2 10 
2.2 8.999 
3 6 
4 4 
5 1 

>>> 





注:'\t'显示了不同在不同的控制台

+0

的一些技巧,但我给投票2秒前,谢谢:) – user1938107 2014-12-05 05:59:46

+0

没有问题,可以理解:) – 2014-12-05 06:01:45

0

将您名单都进字典

x = [1.2,2.2,3,4,5] 
y = [10,8.999,6,4,1] 
dictionary = dict(zip(x, y)) 
print dictionary 
+0

为什么使用'字典'时,OP没有说dictonary ?. – 2014-12-05 05:50:37

0

Ziplist然后使用格式。

In [114]: for i in (zip(x, y)): 
    print i[0],'\t',i[1] 
    .....:  
1.2  10 
2.2  8.999 
3 6 
4 4 
5 1