Shallow or deep copy in a list comprehension
问题 If you have a list (Original) in python like: class CustomID (object): def __init__(self, *args): self.ID = '' self.manymore = float() self.visited = False self.isnoise = False IDlist = ['1','2','3','4','5','6','7','8','9','10'] Original = list() for IDs in IDlist: NewObject = CustomID() NewObject.ID = IDs Original.append(NewObject) and if you do a comprehension for a new list and a function to use over the comprehension sublist: def Func(InputList=list()): for objects in InputList: objects