gpt4 book ai didi

python - 获取空白列表 - 不知道为什么?

转载 作者:太空宇宙 更新时间:2023-11-04 06:26:54 25 4
gpt4 key购买 nike

我使用这段代码:

from __future__ import division
from __future__ import print_function

in_file = open("s:/Personal Folders/Andy/Python Projects/People Cancelled/Analyze Authorize Truncated.csv")
text = in_file.readlines()
in_file.close()

header = text[0:1]
text = text[1:]

for index, line in enumerate(text):
text[index] = line.split(",")

name = text
dates = text

for index, line in enumerate(name):
name[index] = line[3:5]

for stuff, area in enumerate(dates):
dates[stuff] = area[7:8]

print(name)
print(dates)

我得到了这个输出:

 [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]

知道为什么吗?出于某种原因,两个 for 循环之间似乎存在某种干扰 - 如果我单独执行其中一个,我会得到我想要的结果。

谢谢!

最佳答案

看这两行:

name = text
date = text

这些行复制要指向的名称和日期的文本;相反,他们将名称和日期设置为实质上文本的替代名称。因此,在第三个 for 循环之后(主体 name[index] = line[3:5]text 中的每一行都是两个项目长(因为 text name 是同一个列表。事实上,我什至不明白为什么要将 namedate 设置为相等最初为 text;通过使 namedate 等于新的空列表并根据文本

关于python - 获取空白列表 - 不知道为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7354047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com