Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否存在返回列表尾部的python函数?为了做一些简洁的事情,例如:
>>> triplets = [[1,2,3],[1,2,3],[1,2,3]] >>> [cdr(t) for t in triplets] [[2,3],[2,3],[2,3]]
注意这是一个不同的场景,不需要在类似问题中提到的就地运算符 - 这里的理解会失败,因为这些方法不会返回变异列表。
使用列表切片:
>>> triplets = [[1,2,3],[1,2,3],[1,2,3]] >>> [t[1:] for t in triplets] [[2,3],[2,3],[2,3]]