Can I search a list for a range of values?
Ian Kelly
ian.g.kelly at gmail.com
Fri Oct 14 19:37:51 EDT 2011
On Fri, Oct 14, 2011 at 5:24 PM, Tim Chase
<python.list at tim.thechases.com> wrote:
> Depending on your historical programming-language baggage, "i" is usually
> either an index or integer data, and since the source was a list of
> integers, "i" didn't seem inappropriate. Same for other common data-types:
>
> [f for f in (1.1, 2.2, 3.3) if 2.0 <= f < 3.0]
> [s for s in ("cat", "hat", "mat") if "bat" < s < "fat"]
> [c for c in "hello, world!" if 'a' <= c <= 'z']
"f" makes me think "function", not "float". As a general rule,
though, I prefer to name variables for what they represent, not for
their type.
More information about the Python-list
mailing list