On Tue, Dec 17, 2013 at 10:51 AM, Rafael Knuth 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 types (26) and funct
On 12/17/2013 11:30 PM, Dave Angel wrote:
On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano 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 months progr lisp
On 17/12/2013 23:04, Dave Angel wrote:
On Wed, 18 Dec 2013 09:32:03 +1100, Steven D'Aprano
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 bi
On Wed, 18 Dec 2013 09:32:03 +1100, Steven D'Aprano
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 parenthesis, now
did I?
--
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
> 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 corre
On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano
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 - Tutor@python.org
To unsubscrib
>>> 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 ch
On Tue, Dec 17, 2013 at 10:37 AM, Wolfgang Maier
wrote:
> Peter Otten <__peter__ 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
__
Peter Otten <__peter__ 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:
https://mail.python.org/mailman/li
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 wor
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
>> 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 Va
> 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
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
Rafael Knuth 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 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):
>
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.
>>>
>
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
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:
>
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 a
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 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 wor
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 if
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
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
http://docs
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 n
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
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.
>
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 is
29 matches
Mail list logo