'Pygame: Other items in sprite class were updated while looping through and updating the first item

So I have a class Snake, and it has an attribute body, which is a group of sprite (pygame.sprite.Group()), this attr can contain some sprite classes named SnakeBody (pygame.sprite.Sprite), and SnakeBody() also has an attribute snake_pos, its initial value is []

Here I want to update all the sprite inside the body attribute of the Snake class when user pressed an arrow key

for event in pygame.event.get():
...
    if event.key == pygame.K_DOWN: # this error happens with other arrow keys, too
        for snakeBody in snake.body.sprites(): # 'snake' here is Snake() class
             snakeBody.snake_pos.append((snake.x, snake.y))

in this case, when the key is pressed, there are 2 items in snake.body, so that my expected result is that the snake_pos attribute of both 2 items snake.body will be [(2, 3)] (this is an example) but the attr snake_pos of two items was [(2, 3), (2, 3)] which means when we're adding (2, 3) to the first item's attr, the second item's attr is also added at the same time, I saw this by using vscode debugger. I think that my knowledge of for loop is not deep, I'll be happy if I can get some help, I've struggling with this problem for days ;-;



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source