更新时间:2022-12-08 23:21:51
result = [list(someListOfElements) for _ in xrange(x)]
这将创建x个不同的列表,每个列表都有一个someListOfElements
列表的副本(该列表中的每个项目均作为参考,但其中的列表是副本).
This will make x distinct lists, each with a copy of someListOfElements
list (each item in that list is by reference, but the list its in is a copy).
如果更有意义,请考虑使用copy.deepcopy(someListOfElements)
If it makes more sense, consider using copy.deepcopy(someListOfElements)
生成器和列表理解以及事物被认为是 pythonic .
Generators and list comprehensions and things are considered quite pythonic.