Re: Passing a list into a list .append() method

2014-09-09 Thread Rustom Mody
On Tuesday, September 9, 2014 11:25:29 AM UTC+5:30, JBB wrote: > I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'bink

Re: Passing a list into a list .append() method

2014-09-09 Thread JBB
Peter Otten <__peter__ web.de> writes: [Deletia] To Peter Otten and Paul Kroeger: Thank you both, very much. I think I now get why the binding works as it does in addition to why the list() approach worked. (Third attempt - priors not going through, please excuse any repetition) JBB -- h

Re: Passing a list into a list .append() method

2014-09-09 Thread JBB
Paul Kroeger prz-wugen.com> writes: > > Hello, > > I'm myself still learning Python, so others may please correct me, if > I'm wrong. ... > I hope, the above helps to understand why this behaviour.is to be > expected. > To Peter Otten and Paul Kroeger: Thank you both, very much. I think I no

Re: Passing a list into a list .append() method

2014-09-09 Thread Paul Kroeger
Hello, I'm myself still learning Python, so others may please correct me, if I'm wrong. Consider the following sentence of your link "jeffknupp.com/...": "some_guy and first_names[0] both refer to the same object" This is what is going on here. Am Dienstag, den 09.09.2014, 05:50 + schrieb

Re: Passing a list into a list .append() method

2014-09-09 Thread Peter Otten
JBB wrote: > I have a list with a fixed number of elements which I need to grow; ie. > add rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'binky', ''], ... ] > > This is a reduced representatio

Re: Passing a list into a list .append() method

2014-09-09 Thread JBB
Frank Millman chagford.com> writes: > > > "JBB" gmail.com> wrote in message > news:loom.20140909T073428-713 post.gmane.org... > >I have a list with a fixed number of elements which I need to grow; ie. add > > rows of a fixed number of elements, some of which will be blank. ... > I am sure th

Re: Passing a list into a list .append() method

2014-09-08 Thread Frank Millman
"JBB" wrote in message news:loom.20140909t073428-...@post.gmane.org... >I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'b

Passing a list into a list .append() method

2014-09-08 Thread JBB
I have a list with a fixed number of elements which I need to grow; ie. add rows of a fixed number of elements, some of which will be blank. e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', 'bb', 'binky', ''], ... ] This is a reduced representation of a larger list-of-li

Re: Why doesn't python's list append() method return the list itself?

2010-07-16 Thread John Nagle
On 7/13/2010 4:22 AM, Gregory Ewing wrote: John Nagle wrote: Arguably, if a function just does a "return", it should be an error to try to use its return value. It's been suggested at least once before that the default return value for a function should be some special value that raises an exc

Re: Why doesn't python's list append() method return the list itself?

2010-07-14 Thread Nathan Rice
The better question is, do I ever use them? Thinking back over the code I've written in the last couple of years, I would say probably two or three times (mostly in unit tests). I've had to code around string's sequence behavior DOZENS of times. Is it nifty that strings can be sliced like that?

Re: Why doesn't python's list append() method return the list itself?

2010-07-13 Thread Aahz
[Original not available on my swerver, responding here] >On 7/11/10 10:03 PM, Nathan Rice wrote: >> >> Yeah, I long ago filed the in place place in the same folder as >> strings-as-sequences, all() returning True for an empty iterable and any >> returning True rather than the thing which triggered

Re: Why doesn't python's list append() method return the list itself?

2010-07-13 Thread Gregory Ewing
John Nagle wrote: Arguably, if a function just does a "return", it should be an error to try to use its return value. It's been suggested at least once before that the default return value for a function should be some special value that raises an exception if you try to do anything with it exc

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread John Nagle
On 7/11/2010 5:24 PM, Steven D'Aprano wrote: On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/language

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread dhruvbird
On Jul 12, 4:20 pm, Hrvoje Niksic wrote: > dhruvbird writes: > > No, I meant x.append(4) > > Except that I want to accomplish it using slices. > > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > > way?) > > It seems that you've found a way to do so, so why do you need ano

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread Nathan Rice
Stephen: I'm not adverse to being able to do that, but the number of times that I've wanted to do that is greatly outweighed by the number of times I've had to pass a function "(somestring,)" or call "if isinstance(foo, basestring): ..." to avoid producing a bug. The more abstract and adaptive th

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread Hrvoje Niksic
dhruvbird writes: > No, I meant x.append(4) > Except that I want to accomplish it using slices. > > (I can do it as x[lex(x):] = [item_to_append] but is there any other > way?) It seems that you've found a way to do so, so why do you need another way? Are you after elegance? Efficiency? Brevi

Re: Why doesn't python's list append() method return the list itself?

2010-07-12 Thread dhruvbird
On Jul 12, 5:30 am, News123 wrote: > dhruvbird wrote: > > > On a side note, is there any other way to append to a list using > > slices (apart from the one below): > > x[len(x):len(x)] = [item to append] > > dy you mean > x.extend([1,2,3]) No, I meant x.append(4) Except that I want to accomplish

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Chris Rebert
On Sun, Jul 11, 2010 at 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > all() returning True for an empty iterable If you weren't taught about vacuous truth (or even identity elements) in Discrete Mathematics, someone fscked up. Said behavior is t

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Stephen Hansen
On 7/11/10 10:03 PM, Nathan Rice wrote: > Yeah, I long ago filed the in place place in the same folder as > strings-as-sequences, all() returning True for an empty iterable and any > returning True rather than the thing which triggered it. You know, the latter two I can see an argument for, and co

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Nathan Rice
Yeah, I long ago filed the in place place in the same folder as strings-as-sequences, all() returning True for an empty iterable and any returning True rather than the thing which triggered it. Almost always annoying and worked around, but that's the price you pay for the other nice stuff :) It j

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Raymond Hettinger
On Jul 11, 8:59 am, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? Because Guido thinks that having those methods return None is the best way to communicate that the underlying object

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread News123
dhruvbird wrote: > > On a side note, is there any other way to append to a list using > slices (apart from the one below): > x[len(x):len(x)] = [item to append] dy you mean x.extend([1,2,3]) ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Steven D'Aprano
On Sun, 11 Jul 2010 08:59:06 -0700, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? I found this link > (http://code.google.com/edu/languages/google-python- class/lists.html) > wh

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread dhruvbird
On Jul 11, 9:19 pm, Thomas Jollans wrote: > On 07/11/2010 05:59 PM, dhruvbird wrote: > > > Why doesn't python's list append() method return the list itself? For > > that matter, even the reverse() and sort() methods? > > I found this link (http://code.goog

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread MRAB
Thomas Jollans wrote: On 07/11/2010 05:59 PM, dhruvbird wrote: Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/languages/google-python- class/lists.html) which sug

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Antoine Pitrou
On Sun, 11 Jul 2010 08:59:06 -0700 (PDT) dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.htm

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Thomas Jollans
On 07/11/2010 06:28 PM, Nathan Rice wrote: > Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) > > Though TBH sometimes get annoyed at this behavior myself. There are a > lot of people who are very vocal in support of returning none, and it > makes sense in some ways. Since reversed returns

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Nathan Rice
Do list(reversed(list(reversed([1, 2, 3, 4])) + [[]])) Though TBH sometimes get annoyed at this behavior myself. There are a lot of people who are very vocal in support of returning none, and it makes sense in some ways. Since reversed returns an iterator though, it makes this code horrible and

Re: Why doesn't python's list append() method return the list itself?

2010-07-11 Thread Thomas Jollans
On 07/11/2010 05:59 PM, dhruvbird wrote: > Why doesn't python's list append() method return the list itself? For > that matter, even the reverse() and sort() methods? > I found this link (http://code.google.com/edu/languages/google-python- > class/lists.html) which suggest

Why doesn't python's list append() method return the list itself?

2010-07-11 Thread dhruvbird
Why doesn't python's list append() method return the list itself? For that matter, even the reverse() and sort() methods? I found this link (http://code.google.com/edu/languages/google-python- class/lists.html) which suggests that this is done to make sure that the programmer understand

Re: MemoryError when list append... plz help

2008-12-31 Thread Gabriel Genellina
En Wed, 31 Dec 2008 06:34:48 -0200, Steven D'Aprano escribió: Each time you are appending to the list, you append a tuple: ((i, j), sim) where sim is a float and i and j are ints. How much memory does each of those take? sys.getsizeof( ((0, 1), 1.1) ) 32 (On Windows, 32 bits, I get 36)

Re: MemoryError when list append... plz help

2008-12-31 Thread bearophileHUGS
[BON]: > above sim is floating type. > s.append is totally coducted 60,494,500 times. > but this code raise MemoryError. > > My computer has 4G RAM. > i think it's enough. but it doesn't... Try creating it in a more clean way, here an array of doubles: >>> from array import array >>> a = array("d

Re: MemoryError when list append... plz help

2008-12-31 Thread Steven D'Aprano
On Tue, 30 Dec 2008 22:02:49 -0800, [BON] wrote: > == > s=[] > for i in range(11000-1): > for j in range(i+1, 11000): > > s.append(((i,j),sim)) > == > above sim is floating type. > s.append is totally coducted 60,494,500 times. but t

Re: MemoryError when list append... plz help

2008-12-31 Thread Francesco Bochicchio
[BON] ha scritto: == s=[] for i in range(11000-1): for j in range(i+1, 11000): s.append(((i,j),sim)) == above sim is floating type. s.append is totally coducted 60,494,500 times. but this code raise MemoryError. My computer has

Re: MemoryError when list append... plz help

2008-12-30 Thread James Mills
On Wed, Dec 31, 2008 at 4:17 PM, James Mills wrote: > I have no idea how many bytes of memory > storing each element of a list consumes > let alone each float object, but I assure you > it's not going to be anywhere near that of > 60494500 4-bytes spaces (do floats in C > normally consume 4 bytes)

Re: MemoryError when list append... plz help

2008-12-30 Thread James Mills
> but this code raise also MemoryError. > > How can i resolve this problem? > please, help... > > Regards, > -- > View this message in context: > http://www.nabble.com/MemoryError-when-list-append...-plz-help-tp21227745p21227745.html > Sent from the Python -

MemoryError when list append... plz help

2008-12-30 Thread [BON]
in context: http://www.nabble.com/MemoryError-when-list-append...-plz-help-tp21227745p21227745.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: List append

2007-09-15 Thread Steve Holden
Rob E wrote: > On Sat, 15 Sep 2007 03:25:27 +, mouseit wrote: > >> I'm trying to add an element to a list which is a property of an >> object, stored in an array. When I append to one element, all of the >> lists are appended! >> >> Example Code: >> >> class Test: >> array = [] >> >> myTes

Re: List append

2007-09-15 Thread Rob E
On Sat, 15 Sep 2007 03:25:27 +, mouseit wrote: > I'm trying to add an element to a list which is a property of an > object, stored in an array. When I append to one element, all of the > lists are appended! > > Example Code: > > class Test: > array = [] > > myTests = [Test() , Test() ,

Re: List append

2007-09-14 Thread mouseit
On Sep 14, 11:42 pm, Stephen <[EMAIL PROTECTED]> wrote: > In your code, "array" is a class attribute, so it is shared among all > instances. You need to use the __init__ method to define instance > (data) attributes instead: > > def __init__(self): > self.array = [] > > On Sep 14, 11:25 pm, mou

Re: List append

2007-09-14 Thread Stephen
In your code, "array" is a class attribute, so it is shared among all instances. You need to use the __init__ method to define instance (data) attributes instead: def __init__(self): self.array = [] On Sep 14, 11:25 pm, mouseit <[EMAIL PROTECTED]> wrote: > I'm trying to add an element to a li

List append

2007-09-14 Thread mouseit
I'm trying to add an element to a list which is a property of an object, stored in an array. When I append to one element, all of the lists are appended! Example Code: class Test: array = [] myTests = [Test() , Test() , Test()] print len(myTests[1].array) myTests[0].array.append( 5 ) print l