[Tutor] Deleted dictionary length not reporting

Jim Mooney cybervigilante at gmail.com
Wed Jul 17 08:48:44 CEST 2013


On 16 July 2013 20:42, Steven D'Aprano <steve at pearwood.info> wrote:

> Here's a question for you, to test your Python knowledge:

What knowledge? I've been fooling around in this awful AZ heatwave and
only got to chap 5 in the Lutz book. ;')
>
> Assuming that some_list is already a list, what's the difference between
> these two lines, and under what circumstances why would you want to use the
> second one?
>
> some_list = []
> some_list[:] = []
>
However, fooling around helps, so I'd say:

>>> p = [1,2,3]
>>> id(p)
34586456
>>> p[:] = []
>>> id(p)
34586456
>>> p = []
>>> id(p)
34586752

The slice will pass an "is" test, the equal will not.

No fair making me think.This is as bad as being back in school.

-- 
Jim

I sure love that Guv-a-Mint Cheese, Guv-a-Mint Cheese, Guv-a-Mint Cheese
Oh please Guv-a-Mint, Guv-a-Mint please,
Please bring back that Guv-a-Mint Cheeeeeeeeese!


More information about the Tutor mailing list