0

I have a select function:

class MyClass():
    def __init__(self):
        self.data = [
          { "size": "small" },
          { "color": "blue" },
          { "material": "cotton" },
        ]

    def select(self):
        result = self.data.copy()
        return result.copy()

I would expect (especially given the overuse of copy) any changes to the return value not to affect self.data. However, when I do this elsewhere:

    data = self.select().copy()

    for dict_ in data.copy():
        dict_["color"] = "red"
        dict_.pop("size")

self.data now has color red and no size. What am I missing here?

bur
  • 604
  • 5
  • 20

0 Answers0