【发布时间】:2014-10-24 16:39:37
【问题描述】:
我正在努力让我的功能正常工作。这是它的基础:
#for example:
data=[(b),(c),(d),(e)]
results=[]
for x in data: #this goes through each row of the data
# body_code executes. This part is mostly just changing types, etc
a=final_body_code
results.append(a)
print results
#output should be: results=[(b),(c),(d),(e)] #After changing types of b,c,d,e etc.
#The body of the code does not matter at this point, it's just the appending which i'm
#struggling with.
但是,当我这样做时,它似乎没有将 a 附加到结果列表中。我是python的新手,所以请帮忙!
【问题讨论】:
-
为我们提供输入/预期输出?
-
首先,
->是什么?这应该是评论吗?其次,你确定data不是空的还是None?第三,你的意思是它通过每一行?还有更多问题......提供更多细节。 -
printoutdata并确保这些不是空的(又名None)。data是嵌套列表吗? -
给我们一个minimal runnable example that demonstrates the problem when you run it。您的问题没有包含足够的信息来诊断问题。
-
确保到达内部 for 循环。在循环中放置一个打印语句。如果
data为空,则结果将为空,因为将跳过循环
标签: python list loops printing append