[英]Python FOR Loop in a list in a print function
I have another question about somewhat the same problem as I had here -> Python double FOR loops without threading 我还有一个问题,与我在这里遇到的问题相同-> 没有线程的Python double FOR循环
Basically, I want the first for loop down here to enumerate over every school subject in a list, and then inside the print function, I want it to print every number that is in that list, so It comes out like 8 - 4 - 5 - 7 etc. 基本上,我希望这里的第一个for循环枚举列表中的每个学校科目,然后在打印功能中,我希望它打印该列表中的每个数字,所以结果像8-4-5 -7等
for item in store:
print(str(item + "|" + (str((cflist[i]) for i in range(3))) + "\n" + ("-------------" * 7)))
...
Running the complete code makes a big grid filled with these things, but different
subjects each line. (NTL here)
-------------------------------------------------------------------------------------------
NTL|<generator object <genexpr> at 0x0000000003404900>
-------------------------------------------------------------------------------------------
I have had the code working partially, so that each list number was in another subject line, so I would have NTL|8.2
and the next line ENT|5.7
But I want all those numbers to display after each other like NTL|8.2 - 5.7 - etc
我已经使代码部分工作了,以便每个列表号都在另一个主题行中,所以我将拥有NTL|8.2
和下一行ENT|5.7
但是我希望所有这些数字都像NTL|8.2 - 5.7 - etc
一样NTL|8.2 - 5.7 - etc
显示NTL|8.2 - 5.7 - etc
EDIT: Done! 编辑:完成!
-------------------------------------------------------------------------------------------
NTL|7.2 8.4 6.7 5.3 4.8
-------------------------------------------------------------------------------------------
Using str
on a generator expression will print str
version of generator expression, not it's items as you expected: 在生成器表达式上使用str
会打印生成器表达式的str
版本,而不是您期望的项目:
>>> str((x for x in range(3)))
'<generator object <genexpr> at 0xb624b93c>'
Try something like this: 尝试这样的事情:
for item in store:
strs = " ".join([cflist[i]) for i in range(3)])
print(str(item + "|" + strs + "\n" + ("-------------" * 7)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.