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.
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
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
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
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
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
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
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
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.
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
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
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
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:
>
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
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)
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
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
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
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
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
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
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
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
23 matches
Mail list logo