[Tutor] working with multiple sets

kevin parks kp8 at mac.com
Wed Sep 9 16:23:44 CEST 2009


Are any of these methods better than another for some reason?


On Sep 9, 2009, at 10:12 PM, Lie Ryan wrote:

> kevin parks wrote:
>> This discussion is making my brain melt.
>> It is also showing how clever Bob was to do it the way he did... I  
>> found a solution that i think works, and think has not yet been  
>> suggested. I quarantined Bob's code into a black box ... and then  
>> cast the output as a plain old fashioned python built in dictionary  
>> on output. So now instead of printing the code Bob gave the  
>> collection is returned by the func.
>> Then i can cast it as a dict and pick over that dictionary as i  
>> wish. Here (as a bonus) I can transverse a range of keys that is  
>> inclusive of all my keys and also use python's get() dict method to  
>> also indicate index points (keys) that are empty.. which by default  
>> returns 'None', which is also useful in this case to show me what  
>> is missing. But I also have to do some type testing tomfoolery  
>> since missing keys return None, which is a special type (and not a  
>> list like the others)... I wanted the value list sorted so...


1
>> i did  if type(item) == type(foo): .... not sure if there is a  
>> betterererer way.
>

2
> You can use:
> alist = [1, 2, 3]
> if isinstance(alist, list):
>    ...
>

3
> or alternatively check for the None case:
> if alist is not None:
>    ...


More information about the Tutor mailing list