None in string => TypeError?

Ian Kelly ian.g.kelly at gmail.com
Mon Jun 9 13:22:18 EDT 2014


On Mon, Jun 9, 2014 at 10:59 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Tue, Jun 10, 2014 at 2:53 AM, Roy Smith <roy at panix.com> wrote:
>> In retrospect, I suspect:
>>
>>           hourly_data = [(t if status in set('CSRP') else None) for (t,
>> status) in hours]
>>
>> is a little cleaner.
>
> I'd go with this. It's clearer that a status of 'SR' should result in
> False, not True. (Presumably that can never happen, but it's easier to
> read.) I'd be inclined to use set literal syntax, even though it's a
> bit longer - again to make it clear that these are four separate
> strings that you're checking against.

Depending on how much work this has to do, I might also consider
moving the set construction outside the list comprehension since it
doesn't need to be repeated on every iteration.



More information about the Python-list mailing list