Kent thanks again for your input, rest assured is just the haste of my
responses that goes unchecked :)
many thanks,
Gonzalo.
2009/6/9 Kent Johnson :
> On Mon, Jun 8, 2009 at 12:56 PM, Gonzalo
> Garcia-Perate wrote:
>> Kent, Emile thank you both. You're absolutely right, I was going for
>> range
On Mon, Jun 8, 2009 at 12:56 PM, Gonzalo
Garcia-Perate wrote:
> Kent, Emile thank you both. You're absolutely right, I was going for
> range because I thought it made the code more readable/more explicit.
> I hadn't taken into account the performance hit of creating the list
> and iterating through
Kent, Emile thank you both. You're absolutely right, I was going for
range because I thought it made the code more readable/more explicit.
I hadn't taken into account the performance hit of creating the list
and iterating through it. I'm not sure it was more readable either.
the function now reads
On Sun, Jun 7, 2009 at 3:34 PM, Emile van Sebille wrote:
> To explain why we've tended to suggest using int and minval tests and avoid the range inclusion test, consider the following timeit
> results:
The performance penalty for 'in range(...)' is even greater when the
value is not found, becaus
On 6/7/2009 10:17 AM Gonzalo Garcia-Perate said...
Emile, Kent thank you both for your reply, after sending my previous
email I realised that it wasn't working as expected in all cases.
this does work:
def within_range_final(self, n, n2, threshold=5):
return n in range(n2-threshold, n2+thr
On Sun, Jun 7, 2009 at 1:17 PM, Gonzalo
Garcia-Perate wrote:
> Emile, Kent thank you both for your reply, after sending my previous
> email I realised that it wasn't working as expected in all cases.
>
> this does work:
>
> def within_range_final(self, n, n2, threshold=5):
> return n in range(n
Emile, Kent thank you both for your reply, after sending my previous
email I realised that it wasn't working as expected in all cases.
this does work:
def within_range_final(self, n, n2, threshold=5):
return n in range(n2-threshold, n2+threshold+1)
What I have is an ultrasound sensor that g
On Sun, Jun 7, 2009 at 10:08 AM, Gonzalo
Garcia-Perate wrote:
> the solution laid somewhere in between:
>
> def within_range(self, n, n2, threshold=5):
> if n in range(n2-threshold, n2+threshold+1) and n <
> n2+threshold or n > n2 + threshold : return True
> return False
This is a b
On 6/7/2009 8:44 AM Emile van Sebille said...
On 6/7/2009 7:08 AM Gonzalo Garcia-Perate said...
the solution laid somewhere in between:
def within_range(self, n, n2, threshold=5):
if n in range(n2-threshold, n2+threshold+1) and n <
n2+threshold or n > n2 + threshold : return True
On 6/7/2009 7:08 AM Gonzalo Garcia-Perate said...
the solution laid somewhere in between:
def within_range(self, n, n2, threshold=5):
if n in range(n2-threshold, n2+threshold+1) and n <
n2+threshold or n > n2 + threshold : return True
return False
Be careful here -- you proba
the solution laid somewhere in between:
def within_range(self, n, n2, threshold=5):
if n in range(n2-threshold, n2+threshold+1) and n <
n2+threshold or n > n2 + threshold : return True
return False
This seems a bit more pythonic than my original function. Thank you both.
2009/6/
"Gonzalo Garcia-Perate" wrote
Hello tutor, What's the simplest way of creating a list with a range
of numbers above and below a given number?
...
this works fine, but is there a simpler way of doing it? a one liner? :)
I'd probably use a list comprehesion:
L = [n for n in range(lower, uppe
On 6/6/2009 12:31 PM Gonzalo Garcia-Perate said...
Hello tutor, What's the simplest way of creating a list with a range
of numbers above and below a given number?
see the function below:
def within_range( self, number, median, threshold=5 ):
# build a list of (threshold) numbers abo
Hello tutor, What's the simplest way of creating a list with a range
of numbers above and below a given number?
see the function below:
def within_range( self, number, median, threshold=5 ):
# build a list of (threshold) numbers above and below median
range_list = range( media
14 matches
Mail list logo