why i can't reverse a list of list in python

后端 未结 5 579
不思量自难忘°
不思量自难忘° 2021-02-08 04:22

i wanted to do something like this but this code return list of None (i think it\'s because list.reverse() is reversing the list in place):

map(lambda row: row.r         


        
5条回答
  •  梦毁少年i
    2021-02-08 04:52

    You can also use a slice to get the reversal of a single list (not in place):

    >>> a = [1,2,3,4]
    >>> a[::-1]
    [4, 3, 2, 1]
    

    So something like:

    all_reversed = [lst[::-1] for lst in figure]
    

    ...or...

    all_reversed = map(lambda x: x[::-1], figure)
    

    ...will do what you want.

提交回复
热议问题