Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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_List - Fatal编程技术网

Python 将单个列表放在新行上

Python 将单个列表放在新行上,python,list,Python,List,该死的愚蠢问题从死脑 我有一份清单: [1,2,3,4,5,6,7,8,9] 我将其分为3个列表: splits = [1,2,3],[4,5,6],[7,8,9] 我现在想把它打印在单独的行上,这样 print splits 给予 [1,2,3] [4,5,6] [7,8,9] 有人能1)猛击我的头,2)提醒我怎么做吗?这3个列表是列表吗?例如[[1]、[2]、[3]] 如果是,只需: for sliced_list in list_of_lists: print(sliced

该死的愚蠢问题从死脑

我有一份清单:

[1,2,3,4,5,6,7,8,9]
我将其分为3个列表:

splits = [1,2,3],[4,5,6],[7,8,9]
我现在想把它打印在单独的行上,这样

print splits
给予

[1,2,3]
[4,5,6]
[7,8,9]

有人能1)猛击我的头,2)提醒我怎么做吗?

这3个列表是列表吗?例如
[[1]、[2]、[3]]

如果是,只需:

for sliced_list in list_of_lists:
    print(sliced_list)

根据您给定的语法,
[1,2,3],[4,5,6],[7,8,9]
,它是一个列表元组,在使用for语句时表现相同。

这3个列表是列表列表吗?例如
[[1]、[2]、[3]]

如果是,只需:

for sliced_list in list_of_lists:
    print(sliced_list)
根据给定的语法,
[1,2,3],[4,5,6],[7,8,9]
,它是一个列表元组,在使用for语句时其行为相同。

s = [[1,2,3],[4,5,6],[7,8,9]] # list of lists

然后

将导致:

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
遵循:简单比复杂好。

如果

s = [[1,2,3],[4,5,6],[7,8,9]] # list of lists

然后

将导致:

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

遵循:简单比复杂好。

使用字符串连接函数:

print '\n'.join(str(x) for x in [[1,2,3],[4,5,6],[7,8,9]])

使用字符串连接函数:

print '\n'.join(str(x) for x in [[1,2,3],[4,5,6],[7,8,9]])

我不明白你的第一个问题

对于第二个问题,您可能希望这样做:

>>> splits = [1,2,3],[4,5,6],[7,8,9]
>>> print "\n".join([repr(item) for item in splits])
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

我不明白你的第一个问题

对于第二个问题,您可能希望这样做:

>>> splits = [1,2,3],[4,5,6],[7,8,9]
>>> print "\n".join([repr(item) for item in splits])
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

这个问题不是很清楚。列表是否始终为9项?你们一直想把它分成三个子列表吗?问题不太清楚。列表是否始终为9项?你一直想把它分成三个子列表吗?谢谢。你真是太客气了,没有把那一巴掌打在头上。:)非常感谢。你真是太客气了,没有把那一巴掌打在头上。:)