Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将列表中的值添加到每行的其他列表中?_Python_Python 3.x - Fatal编程技术网

Python 如何将列表中的值添加到每行的其他列表中?

Python 如何将列表中的值添加到每行的其他列表中?,python,python-3.x,Python,Python 3.x,我有一个包含700个值的列表(称为行),每一行都是这样的:1370351,下一行是 2325515等 l=[] 对于范围内的i(len(行)): a=行[i]。拆分(“,”) 对于a中的k: j=k。替换(“”,“”) l、 附加(j) 我使用这个for循环首先拆分逗号,然后替换第一个数字('1)上的大空格 最后,我变成了一个大小为2100的列表,但我想要3个值​​在列表的每一行中。如果我理解正确,您希望列表作为输出。例如,一个列表,其中每个元素都是一个列表中的数字长度 你可以这样做: new

我有一个包含700个值的列表(称为
),每一行都是这样的:
1370351
,下一行是
2325515等

l=[]
对于范围内的i(len(行)):
a=行[i]。拆分(“,”)
对于a中的k:
j=k。替换(“”,“”)
l、 附加(j)
我使用这个for循环首先拆分逗号,然后替换第一个数字('1)上的大空格


最后,我变成了一个大小为2100的列表,但我想要3个值​​在列表的每一行中。

如果我理解正确,您希望列表作为输出。例如,一个列表,其中每个元素都是一个列表中的数字长度

你可以这样做:

new_list = []
for line in lines:
    line_array = line.split(",")
    if len(line_array) == 3:
        new_list.append(line_array)
    else:
        print("This line does not have 3 values (not taking it into account):", line)
l=[]
对于范围内的i(len(行)):
a=行[i]。拆分(“,”)
子列表=[]
对于a中的k:
j=k。替换(“”,“”)
sublist.append(j)
l、 附加(子列表)

如果我理解正确,您需要一个列表列表作为输出。例如,一个列表,其中每个元素都是一个列表中的数字长度

你可以这样做:

new_list = []
for line in lines:
    line_array = line.split(",")
    if len(line_array) == 3:
        new_list.append(line_array)
    else:
        print("This line does not have 3 values (not taking it into account):", line)
l=[]
对于范围内的i(len(行)):
a=行[i]。拆分(“,”)
子列表=[]
对于a中的k:
j=k。替换(“”,“”)
sublist.append(j)
l、 附加(子列表)

如果您有这样的列表:

new_list = []
for line in lines:
    line_array = line.split(",")
    if len(line_array) == 3:
        new_list.append(line_array)
    else:
        print("This line does not have 3 values (not taking it into account):", line)
行=[“1370351”,“2325515”]

您可以尝试以下方法:

new_list = []
for line in lines:
    line_array = line.split(",")
    if len(line_array) == 3:
        new_list.append(line_array)
    else:
        print("This line does not have 3 values (not taking it into account):", line)
如果您想检查它:

for a, b, c in new_list:
    print(a, b, c)
你应该得到:

1  370  351
2  325  515

如果您有这样的列表:

new_list = []
for line in lines:
    line_array = line.split(",")
    if len(line_array) == 3:
        new_list.append(line_array)
    else:
        print("This line does not have 3 values (not taking it into account):", line)
行=[“1370351”,“2325515”]

您可以尝试以下方法:

new_list = []
for line in lines:
    line_array = line.split(",")
    if len(line_array) == 3:
        new_list.append(line_array)
    else:
        print("This line does not have 3 values (not taking it into account):", line)
如果您想检查它:

for a, b, c in new_list:
    print(a, b, c)
你应该得到:

1  370  351
2  325  515

你能举一个你期望的例子吗?我真的不明白最终的输出应该是什么。你能举一个你期望的例子吗?我真的不明白最终的输出应该是什么。