brain stuck. whats occurring here?

M

Matthew_WARREN

Hallo,

I'm after

[[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]]

(NxN 'grid', 5x5 in that example, and while typing this up i figured out
how to get it, but I'm still not sure what _was_ happening)


I'm trying
a=[]
row=[ [] for n in range(0,10) ]
a.extend(row[:])
a [[], [], [], [], [], [], [], [], [], []]
a[0].extend(row[:])
a
[[[...], [], [], [], [], [], [], [], [], []], [], [], [], [], [], [], [],
[], []]


why isnt that last a

[[[...]],[],[],[],[],[],[],[],[],[]]


Puzzled :)

Matt.
--


This message and any attachments (the "message") is
intended solely for the addressees and is confidential.
If you receive this message in error, please delete it and
immediately notify the sender. Any use not in accord with
its purpose, any dissemination or disclosure, either whole
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message.
BNP PARIBAS (and its subsidiaries) shall (will) not
therefore be liable for the message if modified.
Do not print this message unless it is necessary,
consider the environment.

---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le
"message") sont etablis a l'intention exclusive de ses
destinataires et sont confidentiels. Si vous recevez ce
message par erreur, merci de le detruire et d'en avertir
immediatement l'expediteur. Toute utilisation de ce
message non conforme a sa destination, toute diffusion
ou toute publication, totale ou partielle, est interdite, sauf
autorisation expresse. L'internet ne permettant pas
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce
message, dans l'hypothese ou il aurait ete modifie.
N'imprimez ce message que si necessaire,
pensez a l'environnement.
 
M

mensanator

Hallo,

I'm after

[[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[]­,[],[],[]]]

(NxN 'grid', 5x5 in that example, and while typing this up i figured out
how to get it, but I'm still not sure what _was_ happening)

I'm trying
a=[]
row=[ [] for n in range(0,10) ]
a.extend(row[:])
a

[[], [], [], [], [], [], [], [], [], []]>>> a[0].extend(row[:])
[[[...], [], [], [], [], [], [], [], [], []], [], [], [], [], [], [], [],
[], []]

why isnt that last a

[[[...]],[],[],[],[],[],[],[],[],[]]

Puzzled :)

I don't see why you should get either.

Especially considering this behaviour:
a=[]
row=[ [] for n in range(0,10) ]
a.extend(row[:])
a [[], [], [], [], [], [], [], [], [], []]
a[0].extend(row[:])
a
[[[...], [], [], [], [], [], [], [], [], []], [], [], [], [], [], [],
[], [], []]
a[0][0][0][0][0][0][0][0][0][0][0][0][0][0]
[[...], [], [], [], [], [], [], [], [], []]
a=[]
row=[ [] for n in range(0,10) ]
a.extend(row[:])
a
[[], [], [], [], [], [], [], [], [], []]

Bug in IDLE?
 
G

Gabriel Genellina

En Thu, 07 Feb 2008 16:16:11 -0200, (e-mail address removed)
On Feb 7, 11:38 am, (e-mail address removed) wrote:
I don't see why you should get either.

Especially considering this behaviour:
a=[]
row=[ [] for n in range(0,10) ]
a.extend(row[:])
a [[], [], [], [], [], [], [], [], [], []]
a[0].extend(row[:])
a
[[[...], [], [], [], [], [], [], [], [], []], [], [], [], [], [], [],
[], [], []]

Those [...] should give a clue. Usually Python doesn't "shorten" a list
representation: if it takes a thousand lines to output a list, there will
be a thousand lines of output. The [...] means that the list is
*recursive*: it has an element that refers to the list itself, so it can't
be represented in the normal way.
Why is it recursive? row[:] is a new list, not the same object as row. It
is a copy - but a "shallow" copy, because their elements aren't copies
themselves. So row[0] is the same object as row[:][0]
x = row[:]
x == row True
x is row False
x[0] is row[0]
True

In the line a[0].extend(row[:]), a[0] is THE SAME LIST as row[:][0], the
first item you are appending. That is, the first thing extend() does is
conceptually a[0].append(a[0]) - and you got a recursive structure.
Bug in IDLE?

No, just a misunderstanding of what [:] does, I presume.
 
M

mensanator

En Thu, 07 Feb 2008 16:16:11 -0200, (e-mail address removed)  
On Feb 7, 11:38 am, (e-mail address removed) wrote:
I don't see why you should get either.
Especially considering this behaviour:
a=[]
row=[ [] for n in range(0,10) ]
a.extend(row[:])
a
[[], [], [], [], [], [], [], [], [], []]
a[0].extend(row[:])
a
[[[...], [], [], [], [], [], [], [], [], []], [], [], [], [], [], [],
[], [], []]

Those [...] should give a clue. Usually Python doesn't "shorten" a list  
representation: if it takes a thousand lines to output a list, there will  
be a thousand lines of output. The [...] means that the list is  
*recursive*: it has an element that refers to the list itself, so it can't  
be represented in the normal way.
Why is it recursive? row[:] is a new list, not the same object as row. It  
is a copy - but a "shallow" copy, because their elements aren't copies  
themselves. So row[0] is the same object as row[:][0]
x = row[:]
x == row True
x is row False
x[0] is row[0]

True

In the line a[0].extend(row[:]), a[0] is THE SAME LIST as row[:][0], the  
first item you are appending. That is, the first thing extend() does is  
conceptually a[0].append(a[0]) - and you got a recursive structure.

I thought that it was some kind of recursive hocus pocus.
That explains why no matter how many indexes I ask for,
I always get the same result.
a[0][0][0][0][0][0][0][0][0][0][0][0][0][0]
[[...], [], [], [], [], [], [], [], [], []]
Bug in IDLE?

No, just a misunderstanding of what [:] does, I presume.

You didn't answer my question, but I just realize that I
mis-typed my example, so never mind.
 
B

Ben Finney

Mark Tolonen said:
I'm after
[[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]]

How about:
[[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []],
[[], [], [], [], []], [[], [], [], [], []]]

Not too useful.
>>> foo = [[[]] * 5] * 5
>>> foo [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]
>>> foo[0][0].append("spam")
>>> foo
[[['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']]]

As made clear in the rest of the thread, the OP wants every one of
those lists to be different objects.
 
T

Terry Reedy

|
| | > Hallo,
| >
| > I'm after
| >
| >
[[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]]
| >
|
| How about:
|
| >>> [[[]]*5]*5
| [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[],
[],
| [], [], []], [[], [], [], [], []]]

Because that is actually only 1, not 25, empty lists
a=[[[]]*5]*5
a[0][0].append('ha')
a
[[['ha'], ['ha'], ['ha'], ['ha'], ['ha']], [['ha'], ['ha'], ['ha'], ['ha'],
['ha']], [['ha'], ['ha'], ['ha'], ['ha'], ['ha']], [['ha'], ['ha'], ['ha'],
['ha'], ['ha']], [['ha'], ['ha'], ['ha'], ['ha'], ['ha']]]

tjr
 
M

Mariano Suárez-Alvarez

This message and any attachments (the "message") is
intended solely for the addressees and is confidential.
If you receive this message in error, please delete it and
immediately notify the sender. Any use not in accord with
its purpose, any dissemination or disclosure, either whole
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message.
BNP PARIBAS (and its subsidiaries) shall (will) not
therefore be liable for the message if modified.
Do not print this message unless it is necessary,
consider the environment.

---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le
"message") sont etablis a l'intention exclusive de ses
destinataires et sont confidentiels. Si vous recevez ce
message par erreur, merci de le detruire et d'en avertir
immediatement l'expediteur. Toute utilisation de ce
message non conforme a sa destination, toute diffusion
ou toute publication, totale ou partielle, est interdite, sauf
autorisation expresse. L'internet ne permettant pas
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce
message, dans l'hypothese ou il aurait ete modifie.
N'imprimez ce message que si necessaire,
pensez a l'environnement.

Is this absurd signature really necessary?
It's only use is making it evident that the BNP IT team (or,
more probably, its legal department) has apparently
not heard about electronic signatures...

-- m
 
S

Steve Holden

Ben said:
Mariano Suárez-Alvarez said:
[disclaimer dozens of lines long]
Is this absurd signature really necessary?

No.

<URL:http://www.goldmark.org/jeff/stupid-disclaimers/>
"Necessary" is dependent on control, of course, and I believe many
people are in the same situation as Matthew. If they want to use
corporate email they have to put up with the crap that their
ill-informed legal department makes the sysadmins configure the outgoing
mailer to add.

That particular trailing crud would be much nicer if they'd put a space
after the leading "--", that way at least we wouldn't have to trim them
out of our replies. This merely tells us that the sysadmins are as
ill-informed as the legal staff ... or perhaps it's just Matthew trying
his best to help us, since I see it appears above the list mailer
trailer. The system is probably trimming the trailing spaces off the
message body. Oh well, ...

regards
steve
 
G

Gabriel Genellina

Mariano Suárez-Alvarez said:
On Feb 7, 3:38 pm, (e-mail address removed) wrote:
[disclaimer dozens of lines long]
Is this absurd signature really necessary?
That particular trailing crud would be much nicer if they'd put a space
after the leading "--", that way at least we wouldn't have to trim them
out of our replies. This merely tells us that the sysadmins are as
ill-informed as the legal staff ... or perhaps it's just Matthew trying
his best to help us, since I see it appears above the list mailer
trailer. The system is probably trimming the trailing spaces off the
message body. Oh well, ...

Perhaps he didn't know that a correct signature separator must be *exactly*
<newline><dash><dash><space><newline>
Nothing more, nothing less. It's easy to dismiss that last space - after
all, trailing spaces are almost never significant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top