On Nov 30, 2012, at 4:20 PM, Tim Roberts wrote:

> In the future, I'd like to suggest that you choose a genuine subject
> line when you post.  It makes people more inclined to read your messages.
> 
> 
> Michael Wilson wrote:
>> 
>> My thought if there's not already an elegant solution in Python is to
>> create a flag 'r' before ranges. So, the example here would become
>> [1,3,'r',5,10,18,78]. Then I just do a  > < query to find a match. How
>> does that sound?
> 
> I can think of several approaches.  For a range, you could add a
> two-tuple instead of an integer:
>    nums = [1, 3, (5,10), 18, 78]
> You can tell the difference at runtime:
>    for item in nums:
>        if type(item) == tuple:

Nit: the Pythonic recommended way of doing this is "if isinstance (item, 
tuple):"

The difference is that this will also work if item is an instance of a subclass 
of "tuple" while the original code does not handle that case.  For this code, 
that might not be an interesting scenario, but in other places it might be.  
It's worth getting into the habit of using "isinstance".

        paul


_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to