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中反转2d列表?_Python_List_2d - Fatal编程技术网

如何在python中反转2d列表?

如何在python中反转2d列表?,python,list,2d,Python,List,2d,这是我的2d列表: numbers = [(1,2,3,4,5),(6,7,8,9,10),(11,12,13,14,15)] 我想得到的是: numbers = [(15,14,13,12,11),(10,9,8,7,6),(5,4,3,2,1)] 我知道的唯一方法是: 编号为[:-1]的i的: 打印(一) 有人能帮忙吗?您可以使用该功能 print([i[::-1] for i in numbers[::-1]]) 这是另一种方式 print map(lambda x: list(re

这是我的2d列表:

numbers = [(1,2,3,4,5),(6,7,8,9,10),(11,12,13,14,15)]
我想得到的是:

numbers = [(15,14,13,12,11),(10,9,8,7,6),(5,4,3,2,1)]
我知道的唯一方法是:

编号为[:-1]的i的
:
打印(一)

有人能帮忙吗?

您可以使用该功能

print([i[::-1] for i in numbers[::-1]])

这是另一种方式

print map(lambda x: list(reversed(x)),reversed(numbers))
通用反向函数
你想倒过来还是按倒过来(降序)的顺序得到结果?你还得倒过来。。谢谢@SmartManojMy2Cents:比做循环更好的不是真的,应该是相同的性能。不要使用太多注释#返回inputlist。。。那不是很有用。您可以立即返回,而无需将地图转换为列表。在这种情况下,打电话的人可以做任何他想做的事情,而不需要out(更有用的imho)。但除此之外,没关系:)
print map(lambda x: list(reversed(x)),reversed(numbers))
def reverse2DList(inputList):

    #reverese items inside list
    inputList.reverse()
   
    #reverse each item inside the list using map function(Better than doing loops...)
    inputList = list(map(lambda x: x[::-1], inputList))
    
    #return
    return inputList