[Tutor] list objects are unhashable
Kent Johnson
kent37 at tds.net
Tue Jul 1 13:04:37 CEST 2008
On Tue, Jul 1, 2008 at 6:27 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "Kent Johnson" <kent37 at tds.net> wrote
>>>
>>> if isinstance(x, list):
>>> for item in x:
>>> x = item
>>
>> This just assigns x to the last element of the list
>
> Oops, yes, I said the first but in fact reassigning x does not stop the
> loop, it seems the loop works on a local copy of the original reference.
Under the hood, 'for item in x' creates an iterator which has a
reference to the original list.
Kent
More information about the Tutor
mailing list