[英]Python FOR Loop in a list in a print function
我還有一個問題,與我在這里遇到的問題相同-> 沒有線程的Python double FOR循環
基本上,我希望這里的第一個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>
-------------------------------------------------------------------------------------------
我已經使代碼部分工作了,以便每個列表號都在另一個主題行中,所以我將擁有NTL|8.2
和下一行ENT|5.7
但是我希望所有這些數字都像NTL|8.2 - 5.7 - etc
一樣NTL|8.2 - 5.7 - etc
顯示NTL|8.2 - 5.7 - etc
編輯:完成!
-------------------------------------------------------------------------------------------
NTL|7.2 8.4 6.7 5.3 4.8
-------------------------------------------------------------------------------------------
在生成器表達式上使用str
會打印生成器表達式的str
版本,而不是您期望的項目:
>>> str((x for x in range(3)))
'<generator object <genexpr> at 0xb624b93c>'
嘗試這樣的事情:
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.