[Tutor] Another assert() question

Marcel Wunderlich deaddy at gmx.de
Sun Jul 13 21:41:58 CEST 2008


Hi Dick,

because set(list) creates an unsorted collection without duplicate entrys  
of the items in the list.
If you pass an empty list, the resulting set will also be an empty  
collection.
A list containing an empty list evaluates non false, since it's not empty.  
Maybe it helps you to compare them with the len-command.
len(set([])) returns 0, len([[]]) returns 1.

Marcel

> At 11:44 AM 7/13/2008, Steve Willoughby wrote:
>
> Dick Moores wrote:
>
> Yes! A rule, not logic. I'm not contradicting Kent, just helping myself
> understand. First the rule, then logic in the application of the rule.  
> And I
> assume the rule is there in Python because it makes things work better.
> Yes, so a statement like "if foo:" becomes an idiom for "if the  
> collection foo
> has stuff in it:" which is handy whether foo is a text string or a list  
> of
> objects.
> Yes, I've been using that, a bit uneasily.
>
> One question about the data I listed. Why is bool(set([])) false,  
> whereas bool([[]])
> is true?
>
> Dick




More information about the Tutor mailing list