Re: Rant (was Re: x*x if x>10

2008-07-28 Thread greg
Diez B. Roggisch wrote: I maybe should paraphrase "don't return objects you passed as arguments from a function". The important thing is that a function shouldn't modify any object unless it's the express purpose of the function to do so. You could call this the "look but don't touch" rule.

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Diez B. Roggisch
Terry Reedy schrieb: DaveM wrote: On Sun, 27 Jul 2008 19:46:32 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: As a rule of thumb, don't return objects you didn't create inside a function from scratch. Unless its job is specifically to get/fetch an object (reference thereto) from som

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Terry Reedy
DaveM wrote: On Sun, 27 Jul 2008 19:46:32 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: As a rule of thumb, don't return objects you didn't create inside a function from scratch. Unless its job is specifically to get/fetch an object (reference thereto) from someplace the caller canno

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread DaveM
On Sun, 27 Jul 2008 19:46:32 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >As a rule of thumb, don't return objects you didn't create inside a >function from scratch. I wish I'd had that advice when I started learning python. It would have saved me no end of grief. DaveM -- http://mail

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread DaveM
On Sun, 27 Jul 2008 09:28:28 -0700, Gary Herron <[EMAIL PROTECTED]> wrote: >> a = list(set(itertools.chain(*sessexam.values( >> a.sort() #As I write I'm wondering if I really need it sorted. Hmm... >> return a >Didn't someone already answer that. List addition and sum() both do

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Anders J. Munch
Gary Herron wrote: >>> A = [1,2,3] >>> B = [4,5,6] >>> C = [7,8,9] >>> A+B+C [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> sum([A,B,C], []) [1, 2, 3, 4, 5, 6, 7, 8, 9] Careful now, this can be very slow. sum uses __add__, not __iadd__, which gives this approach quadratic worst-case runtime. - Ande

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Terry Reedy
DaveM wrote: On Sun, 27 Jul 2008 16:57:14 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> You'll have guessed, I'm sure, that I'm not a professional programmer. This was the third rewrite of a program to match candidate groups to examiners on a three day course I run, necessitated on this occasi

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Diez B. Roggisch
Can you tell us what you mean by "several names of one object"? You mean this? a = range(10) b = a id(a) == id(b) ? Passing references instead of values is an extremely important concept of many languages, without it you would end up copying most of the time. OK. I've obviously been thin

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread DaveM
On Sun, 27 Jul 2008 16:41:19 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >You obviously aren't aware of the pitfalls regarding the mis-use of or >and and for this usage. Well, yes, I am (and the way around the problem), but as its never caught me out (so far), I hadn't considered it.

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Diez B. Roggisch
DaveM schrieb: On Sun, 27 Jul 2008 16:57:14 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: Marc 'BlackJack' Rintsch schrieb: On Sun, 27 Jul 2008 16:41:19 +0200, Diez B. Roggisch wrote: DaveM schrieb: Getting back to the list concatenation, I finally found the itertools.chain command w

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Gary Herron
DaveM wrote: On Sun, 27 Jul 2008 16:57:14 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: Marc 'BlackJack' Rintsch schrieb: On Sun, 27 Jul 2008 16:41:19 +0200, Diez B. Roggisch wrote: DaveM schrieb: Getting back to the list concatenation, I finally found the iter

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread DaveM
On Sun, 27 Jul 2008 16:57:14 +0200, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >Marc 'BlackJack' Rintsch schrieb: >> On Sun, 27 Jul 2008 16:41:19 +0200, Diez B. Roggisch wrote: >> >>> DaveM schrieb: Getting back to the list concatenation, I finally found the itertools.chain co

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread alex23
On Jul 28, 1:26 am, ssecorp <[EMAIL PROTECTED]> wrote: > I might be misunderstanding OP but: > > a+b+c+d+e is simple way of concatenating 5 lists... > > as a function that takes any amount of lists and concatenates them: > def concat(*args): > c = [] > for elem in args: >

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread ssecorp
I might be misunderstanding OP but: a+b+c+d+e is simple way of concatenating 5 lists... as a function that takes any amount of lists and concatenates them: def concat(*args): c = [] for elem in args: c += elem return c don't know if extend is faster or slo

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Diez B. Roggisch
Marc 'BlackJack' Rintsch schrieb: On Sun, 27 Jul 2008 16:41:19 +0200, Diez B. Roggisch wrote: DaveM schrieb: Getting back to the list concatenation, I finally found the itertools.chain command which is the most compact and fastest (or second fastest by a trivial amount, I can't remember which)

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Marc 'BlackJack' Rintsch
On Sun, 27 Jul 2008 16:41:19 +0200, Diez B. Roggisch wrote: > DaveM schrieb: >> Getting back to the >> list concatenation, I finally found the itertools.chain command which >> is the most compact and fastest (or second fastest by a trivial amount, >> I can't remember which). Along the way, I must

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Gary Herron
DaveM wrote: On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <[EMAIL PROTECTED]> wrote: On Jul 27, 10:13 pm, ssecorp <[EMAIL PROTECTED]> wrote: I have seen somewhere that you can write something like: x*x if x>10 but exactly that doesn't work

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Diez B. Roggisch
DaveM schrieb: On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <[EMAIL PROTECTED]> wrote: On Jul 27, 10:13 pm, ssecorp <[EMAIL PROTECTED]> wrote: I have seen somewhere that you can write something like: x*x if x>10 but exactly that doesn't work and I can't

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Karen Tracey
On Sun, Jul 27, 2008 at 10:17 AM, DaveM <[EMAIL PROTECTED]> wrote: > On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <[EMAIL PROTECTED]> > wrote: > > >On Jul 27, 10:13 pm, ssecorp <[EMAIL PROTECTED]> wrote: > >> I have seen somewhere that you can write s

Rant (was Re: x*x if x>10

2008-07-27 Thread DaveM
On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <[EMAIL PROTECTED]> wrote: >On Jul 27, 10:13 pm, ssecorp <[EMAIL PROTECTED]> wrote: >> I have seen somewhere that you can write something like: >> x*x if x>10 >> but exactly that doesn't work and I can

Re: x*x if x>10

2008-07-27 Thread alex23
On Jul 27, 10:13 pm, ssecorp <[EMAIL PROTECTED]> wrote: > I have seen somewhere that you can write something like: > > x*x if x>10 > > but exactly that doesn't work and I can't get any variation to work. It's called a ternary operator. The format is: = i

Re: x*x if x>10

2008-07-27 Thread Diez B. Roggisch
ssecorp schrieb: I have seen somewhere that you can write something like: x*x if x>10 but exactly that doesn't work and I can't get any variation to work. it is possible to nest with an else too. how do you write it? and also, is it idiomatic? doesn't seem to add f

x*x if x>10

2008-07-27 Thread ssecorp
I have seen somewhere that you can write something like: x*x if x>10 but exactly that doesn't work and I can't get any variation to work. it is possible to nest with an else too. how do you write it? and also, is it idiomatic? doesn't seem to add functionality, just anothe