且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中创建重复的元组列表?

更新时间:2022-12-08 23:07:39

由于元组是不可变的,因此您可以执行以下操作:

Since tuples are immutable you may be able to do:

lst = [tuples[0]]
repeated = lst * 10 # create a list of the first tuple repeated 10 times

如果它们包含可变对象,则由于它们是重复的相同对象,因此其中任何一个的更改都将反映在所有对象中.

If they contain mutable objects changes in any of them will reflect in all of them, since these are the same objects repeated.