infinite assignment in python list?

infinite, list, python

Solution

You have a recursive list there. `values[1]` is a reference to `values`. If you want to store the value of `values` you need to copy it, the easiest way to do so is

values[1] = values[:]

Problem

I've come cross this question. Code: ``` >>> values = [0, 1, 2] >>> values[1] = values >>> values [0, [...], 2] ``` The result I expect is: ``` [0, [0, 1, 2], 2] ``` Is this an infinite assignment for python list? What is behind the scene? Thanks.

Original source

Related problems