On 12/17/2013 11:30 PM, Dave Angel wrote:
On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano st...@pearwood.info wrote:
if a 0 and b 0 and c 0:
if all(x for x in (a, b, c):
Er, perhaps it should be:
if all (x 0 for x in (a, b, c):
I saw the missing paren at once (maybe a few
On Tue, Dec 17, 2013 at 10:51 AM, Rafael Knuth rafael.kn...@gmail.com wrote:
Got it. I just wanted to make sure I get a better understanding of how
to use any() and all() even though I already had a solution at hand.
So far, I worked through 24 out of 68 built-in functions
68 is the total for
Hej there,
I use any() and all() frequently. For example, suppose you have a
function that takes a list of numbers, and they are all supposed to be
positive.
def calculate_values(numbers):
if all(number 0 for number in numbers):
# do the calculation
else:
raise
Rafael Knuth wrote:
Hej there,
I use any() and all() frequently. For example, suppose you have a
function that takes a list of numbers, and they are all supposed to be
positive.
def calculate_values(numbers):
if all(number 0 for number in numbers):
# do the calculation
got it!
Thanks, Peter
On Tue, Dec 17, 2013 at 4:27 PM, Peter Otten __pete...@web.de wrote:
Rafael Knuth wrote:
Hej there,
I use any() and all() frequently. For example, suppose you have a
function that takes a list of numbers, and they are all supposed to be
positive.
def
On Tue, Dec 17, 2013 at 03:21:34PM +0100, Rafael Knuth wrote:
def PositiveCalculator(a, b):
if a 0 and b 0:
return a + b
else:
raise ValueError(negative number)
In this function one negative number is tolerated:
def PositiveCalculator(a, b):
if a 0 or b
Rafael Knuth rafael.knuth at gmail.com writes:
Hej there,
I use any() and all() frequently. For example, suppose you have a
function that takes a list of numbers, and they are all supposed to be
positive.
def calculate_values(numbers):
if all(number 0 for number in numbers):
On 17/12/2013 14:21, Rafael Knuth wrote:
Hej there,
I use any() and all() frequently. For example, suppose you have a
function that takes a list of numbers, and they are all supposed to be
positive.
def calculate_values(numbers):
if all(number 0 for number in numbers):
# do the
BUT: this really doesn't make much sense! Your if construct is a lot more
readable than what any or all would give you in this example.
As pointed out repeatedly here, you can always replace any() and all() with
a combination of for and if, it's really a question of readability (and
style)
def check_values(a, b):
if all(number = 0 for number in range(a, b)):
return True
else:
raise ValueError(negative number)
And:
def PositiveCalculator(a, b):
if a 0 and b 0:
return a + b
else:
raise ValueError(negative number)
I just wrote a unittest for this function here:
def PositiveCalculator(*summands):
if all(x 0 for x in summands):
return sum(summands)
else:
raise ValueError(negative value)
Here's the test (I want to test whether the function works if the user
enters floats instead of
Rafael Knuth wrote:
I just wrote a unittest for this function here:
def PositiveCalculator(*summands):
if all(x 0 for x in summands):
return sum(summands)
else:
raise ValueError(negative value)
Here's the test (I want to test whether the function works if the
Peter Otten __peter__ at web.de writes:
Look at this line:
if __name__ == __main__:
do so very closely :)
Wolfgang
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
On Tue, Dec 17, 2013 at 10:37 AM, Wolfgang Maier
wolfgang.ma...@biologie.uni-freiburg.de wrote:
Peter Otten __peter__ at web.de writes:
Look at this line:
if __name__ == __main__:
do so very closely :)
In monospaced font :)
Took me forever to see it, thanks Gmail...
--
Zach
Look at this line:
if __name__ == __main__:
do so very closely :)
In monospaced font :)
Took me forever to see it, thanks Gmail...
Ok ... found it ;-)
Thanks!
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription
On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano
st...@pearwood.info wrote:
if a 0 and b 0 and c 0:
if all(x for x in (a, b, c):
Er, perhaps it should be:
if all (x 0 for x in (a, b, c):
--
DaveA
___
Tutor maillist -
On Tue, Dec 17, 2013 at 05:30:00PM -0500, Dave Angel wrote:
On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano
st...@pearwood.info wrote:
if a 0 and b 0 and c 0:
if all(x for x in (a, b, c):
Er, perhaps it should be:
if all (x 0 for x in (a, b, c):
Oops, yes, thanks for the
On Wed, 18 Dec 2013 09:32:03 +1100, Steven D'Aprano
st...@pearwood.info wrote:
if all (x 0 for x in (a, b, c):
Oops, yes, thanks for the correction.
Er, I mean, yes, you have found my deliberate mistake and passed
the
test!
But I didn't catch the other missing bit, a right
On 17/12/2013 23:04, Dave Angel wrote:
On Wed, 18 Dec 2013 09:32:03 +1100, Steven D'Aprano
st...@pearwood.info wrote:
if all (x 0 for x in (a, b, c):
Oops, yes, thanks for the correction.
Er, I mean, yes, you have found my deliberate mistake and passed
the
test!
But I didn't catch
Hey there,
I am currently looking into all built in functions in Python 3.3.0,
one by one, in order to understand what each of them specifically does
(I am familiar with some of them already, but most built in functions
are still alien to me). I am working with the Python documentation
Rafael Knuth wrote:
Hey there,
I am currently looking into all built in functions in Python 3.3.0,
one by one, in order to understand what each of them specifically does
(I am familiar with some of them already, but most built in functions
are still alien to me). I am working with the
On 16/12/13 15:28, Rafael Knuth wrote:
First question: all(iterable) and any(iterable) - can you give me one
or two examples what these functions do and how they are specifically
used?
In my experience they aren't used all that often. But the logic is
straightforward. all(seq) returns true
On 12/16/2013 04:28 PM, Rafael Knuth wrote:
Hey there,
I am currently looking into all built in functions in Python 3.3.0,
one by one, in order to understand what each of them specifically does
(I am familiar with some of them already, but most built in functions
are still alien to me). I am
all('')
True
Actually the last one surprised me. I expected false. So maybe a resident
guru can explain that anomaly... I assume it works on the basis of testing
until it finds a false and so an empty sequence
always returns true...
The term you're thinking of is vacuous truth
On Mon, Dec 16, 2013 at 05:15:28PM +, Alan Gauld wrote:
On 16/12/13 15:28, Rafael Knuth wrote:
First question: all(iterable) and any(iterable) - can you give me one
or two examples what these functions do and how they are specifically
used?
In my experience they aren't used all that
I'm new to python and I was wondering if you could tell me how I would:
first, define a function,distance_from_zero, with one parameter (choose any
parameter name you like).
Second, have that function do the following:
1. Check the type of the input it receives.
2. If the type
Dane Saltzman wrote:
I'm new to python and I was wondering if you could tell me how I would:
first, define a function,distance_from_zero, with one parameter (choose
any parameter name you like). Second, have that function do the following:
1. Check the type of the input it receives.
2.
On Tue, Aug 7, 2012 at 4:37 AM, Peter Otten __pete...@web.de wrote:
Dane Saltzman wrote:
I'm new to python and I was wondering if you could tell me how I would:
first, define a function,distance_from_zero, with one parameter (choose
any parameter name you like). Second, have that function do
On 07/08/2012 10:48, Joel Goldstick wrote:
On Tue, Aug 7, 2012 at 4:37 AM, Peter Otten __pete...@web.de wrote:
Dane Saltzman wrote:
I'm new to python and I was wondering if you could tell me how I would:
first, define a function,distance_from_zero, with one parameter (choose
any parameter
29 matches
Mail list logo