[Neuroimaging] what's the problem??????

Roel Schroeven roel at roelschroeven.net
Fri Jul 15 15:14:31 EDT 2022


Dennis Lee Bieber schreef op 15/07/2022 om 19:11:
> ...
> is, itself, returning a dictionary on which .values() can be applied. In
> that case, the list() call is likely redundant as .values() already
> returned a list (hmmm, is list(some_list) a no-op, or does it wrap
> some_list into another list -- in the latter case, the indexing will fail
> as there is only one element to access)

list(some_list) returns a copy of some_list, a shallow copy to be precise.

 >>> a = [ [1, 2, 3], [4, 5, 6] ]
 >>> b = list(a)

Both lists are equal:
 >>> a == b
True

But not identical:
 >>> a is b
False

The sublists are identical though:
 >>> a[0] is b[0]
True
 >>> a[1] is b[1]
True

-- 

"I've come up with a set of rules that describe our reactions to technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is
    just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new
    and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of things."
         -- Douglas Adams, The Salmon of Doubt



More information about the Python-list mailing list