Temporary created during python list iteration?
I want to understand why the following is happening. My guess is that a temporary is being created during list iteration, but want some experts to confirm this:

    def test():
        a=[set([1,2,3]),set([3,4,5])]
        x=set([1,4])
        for i in a:
            # doesn't actually modify list contents, making a copy of list elements in i?
            i=i.difference(x)
        print a
        for idx,i in enumerate(a):
            i=i.difference(x)
            # obviously this modifies the contents
            a[idx]=i
        print a

Output:

    [set([1, 2, 3]), set([3, 4, 5])]
    [set([2, 3]), set([3, 5])]
Temporary created during python list iteration?
===

I want to understand why the following is happening. My guess is that a temporary is being created during list iteration, but want some experts to confirm this:

    def test():
        a=[set([1,2,3]),set([3,4,5])]
        x=set([1,4])
        for i in a:
            # doesn't actually modify list contents, making a copy of list elements in i?
            i=i.difference(x)
        print a
        for idx,i in enumerate(a):
            i=i.difference(x)
            # obviously this modifies the contents
            a[idx]=i
        print a

Output:

    [set([1, 2, 3]), set([3, 4, 5])]
    [set([2, 3]), set([3, 5])]