Re: [Tutor] Built In Functions

2013-12-18 Thread spir
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

Re: [Tutor] Built In Functions

2013-12-18 Thread eryksun
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Peter Otten
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Steven D'Aprano
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Wolfgang Maier
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):

Re: [Tutor] Built In Functions

2013-12-17 Thread Mark Lawrence
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
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)

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
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)

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Peter Otten
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Wolfgang Maier
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:

Re: [Tutor] Built In Functions

2013-12-17 Thread Zachary Ware
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Dave Angel
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 -

Re: [Tutor] Built In Functions

2013-12-17 Thread Steven D'Aprano
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Dave Angel
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

Re: [Tutor] Built In Functions

2013-12-17 Thread Mark Lawrence
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

[Tutor] Built In Functions

2013-12-16 Thread Rafael Knuth
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

Re: [Tutor] Built In Functions

2013-12-16 Thread Peter Otten
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

Re: [Tutor] Built In Functions

2013-12-16 Thread Alan Gauld
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

Re: [Tutor] Built In Functions

2013-12-16 Thread spir
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

Re: [Tutor] Built In Functions

2013-12-16 Thread Danny Yoo
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

Re: [Tutor] Built In Functions

2013-12-16 Thread Steven D'Aprano
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

[Tutor] Built in functions

2012-08-07 Thread Dane Saltzman
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 

Re: [Tutor] Built in functions

2012-08-07 Thread Peter Otten
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.

Re: [Tutor] Built in functions

2012-08-07 Thread Joel Goldstick
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

Re: [Tutor] Built in functions

2012-08-07 Thread Mark Lawrence
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