Re: Help understanding the decisions *behind* python?

2009-08-04 Thread Masklinn
On 3 Aug 2009, at 18:57 , John Nagle wrote: Dave Angel wrote: sturlamolden wrote: On 20 Jul, 18:27, Phillip B Oldham phillip.old...@gmail.com wrote: Tuples are used for passing arguments to and from a function. Common use of tuples include multiple return values and optional arguments (*args).

Re: Help understanding the decisions *behind* python?

2009-08-03 Thread John Nagle
Dave Angel wrote: sturlamolden wrote: On 20 Jul, 18:27, Phillip B Oldham phillip.old...@gmail.com wrote: Tuples are used for passing arguments to and from a function. Common use of tuples include multiple return values and optional arguments (*args). That's from Mesa, the Xerox PARC

Re: Help understanding the decisions *behind* python?

2009-08-03 Thread alex23
John Nagle na...@animats.com wrote: Every function returned a tuple as an argument. This had a nice symmetry; function outputs and function inputs had the same form.   Mesa was the first language to break through the single return value syntax problem.     Python doesn't go that far. I

Re: Help understanding the decisions *behind* python?

2009-08-03 Thread greg
John Nagle wrote: Mesa used tuples for subroutine arguments in a very straightforward way. Every function took one tuple as an argument Python doesn't go that far. I believe that a very early version of Python did do something like that, but it was found to be a bad idea, because there

Re: Help understanding the decisions *behind* python?

2009-08-02 Thread Dave Angel
sturlamolden wrote: On 20 Jul, 18:27, Phillip B Oldham phillip.old...@gmail.com wrote: We're not looking to start any arguments or religious wars and we're not asking that python be changed into something its not. We'd simply like to understand the decision behind the lists and tuple

Re: Help understanding the decisions *behind* python?

2009-08-02 Thread Marcus Wanner
On 8/1/2009 9:31 PM, sturlamolden wrote: - Python and C programmers use lists and arrays similarly. I'm guessing that's because of the brackets... Marcus -- http://mail.python.org/mailman/listinfo/python-list

Re: Help understanding the decisions *behind* python?

2009-08-01 Thread sturlamolden
On 20 Jul, 18:27, Phillip B Oldham phillip.old...@gmail.com wrote: We're not looking to start any arguments or religious wars and we're not asking that python be changed into something its not. We'd simply like to understand the decision behind the lists and tuple structures. We feel that in

Re: Help understanding the decisions *behind* python?

2009-08-01 Thread sturlamolden
On 31 Jul, 23:43, Raymond Hettinger pyt...@rcn.com wrote:  More than one person here has observed that the time to learn to program Pythonically is inversely proportional to their experience in Java. I believe it is opposite. The longer the Java experience, the longer it takes to program

Re: Help understanding the decisions *behind* python?

2009-08-01 Thread Nobody
On Sat, 01 Aug 2009 19:19:43 -0700, sturlamolden wrote:  More than one person here has observed that the time to learn to program Pythonically is inversely proportional to their experience in Java. I believe it is opposite. The longer the Java experience, the longer it takes to program

Re: Help understanding the decisions *behind* python?

2009-08-01 Thread sturlamolden
On 2 Aug, 04:47, Nobody nob...@nowhere.com wrote: OTOH, using a for loop when you could use a generator means less work when you need to make a minor change and a generator is no longer sufficient. It's not just that. It is e.g. using a for loop and indexes instead of a slice. E.g. for i in

Re: Help understanding the decisions *behind* python?

2009-08-01 Thread sturlamolden
On 31 Jul, 21:31, Masklinn maskl...@masklinn.net wrote: It's intuitive if you come to Python knowing other languages with   tuples (which are mostly functional, and in which tuples are *never*   sequences/iterables). At the end of the day, and if Guido's intention   truly was what Raymond

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Joshua Bronson
On Jul 22, 7:55 am, Duncan Booth duncan.bo...@invalid.invalid wrote: I find it interesting that the heapq functions tell you in the documentation that they aren't suitable for use where n==1 or where n is near the total size of the sequence whereas random.sample() chooses what it thinks is the

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Raymond Hettinger
On Jul 22, 4:55 am, Duncan Booth duncan.bo...@invalid.invalid wrote: Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: But that's the wrong solution to the problem. The OP wants the largest (or smallest) item, which he expects to get by sorting, then grabbing the first element:

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Raymond Hettinger
On Jul 20, 9:27 am, Phillip B Oldham phillip.old...@gmail.com wrote: Specifically the differences between lists and tuples have us confused and have caused many discussions in the office. We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Emmanuel Surleau
On Friday 31 July 2009 19:49:04 Raymond Hettinger wrote: On Jul 20, 9:27 am, Phillip B Oldham phillip.old...@gmail.com wrote: Specifically the differences between lists and tuples have us confused and have caused many discussions in the office. We understand that lists are mutable and

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Masklinn
On 31 Jul 2009, at 20:48 , Emmanuel Surleau wrote: On Friday 31 July 2009 19:49:04 Raymond Hettinger wrote: On Jul 20, 9:27 am, Phillip B Oldham phillip.old...@gmail.com wrote: Specifically the differences between lists and tuples have us confused and have caused many discussions in the

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Terry Reedy
Emmanuel Surleau wrote: Beyond the mutable/hashable distinction, there is an important philosophical distinction articulated by Guido. He deems tuples to be useful for struct like groupings of non-homogenous fields and lists to be useful for sequences of homogenous data suitable for looping.

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Emmanuel Surleau
On Friday 31 July 2009 21:55:11 Terry Reedy wrote: Emmanuel Surleau wrote: Beyond the mutable/hashable distinction, there is an important philosophical distinction articulated by Guido. He deems tuples to be useful for struct like groupings of non-homogenous fields and lists to be useful

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Raymond Hettinger
While nothing in the list/tuple code requires you to make that distinction, it is important because that philosophy pervades the language.  If you follow Guido's direction, you'll find that the various parts of the language fit together better.  Do otherwise and you'll be going against

Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-31 Thread Raymond Hettinger
On Jul 26, 11:24 am, John Nagle na...@animats.com wrote: A tuple is really a frozen list.  Arguably, frozen objects should have been a general concept.  Conceptually, they're simple - once __init__ has run, there can be no more changes to fields of the object. I would argue that freezing and

Re: Help understanding the decisions *behind* python?

2009-07-31 Thread Gabriel Genellina
En Fri, 31 Jul 2009 17:26:58 -0300, Emmanuel Surleau emmanuel.surl...@gmail.com escribió: On Friday 31 July 2009 21:55:11 Terry Reedy wrote: The word tuple comes from relational databases as a generalization of single, double, triple, quadruple, quintuple, sextuple, sestuple, octuple, etc. A

Re: Help understanding the decisions *behind* python?

2009-07-28 Thread Luis Zarrabeitia
On Friday 24 July 2009 11:07:30 am Inky 788 wrote: On Jul 23, 3:42 am, Hendrik van Rooyen hend...@microcorp.co.za if you think it is contrived, then please consider how you would keep track of say the colour of a pixel on a screen at position (x,y) - this is about the simplest natural tuple

Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-27 Thread John Nagle
Steven D'Aprano wrote: On Sun, 26 Jul 2009 11:24:48 -0700, John Nagle wrote: An interesting issue is Python objects, which are always mutable. A dict of Python objects is allowed, but doesn't consider the contents of the objects, just their identity (address). Only built-in types are

Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-27 Thread Benjamin Kaplan
On Sun, Jul 26, 2009 at 2:24 PM, John Naglena...@animats.com wrote: Beni Cherniavsky wrote: On Jul 22, 9:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: My guess is that it was probably for optimization reasons long ago. I've never

Re: Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-27 Thread Dave Angel
Benjamin Kaplan wrote: On Sun, Jul 26, 2009 at 2:24 PM, John Naglena...@animats.com wrote: Beni Cherniavsky wrote: On Jul 22, 9:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: snip problem. An interesting

Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-26 Thread John Nagle
Beni Cherniavsky wrote: On Jul 22, 9:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: My guess is that it was probably for optimization reasons long ago. I've never heard a *good* reason why Python needs both. The good reason is the

Re: Help understanding the decisions *behind* python? - immutable objects

2009-07-26 Thread Steven D'Aprano
On Sun, 26 Jul 2009 11:24:48 -0700, John Nagle wrote: An interesting issue is Python objects, which are always mutable. A dict of Python objects is allowed, but doesn't consider the contents of the objects, just their identity (address). Only built-in types are immutable; one cannot

Re: Help understanding the decisions *behind* python?

2009-07-25 Thread Hendrik van Rooyen
On Friday 24 July 2009 17:07:30 Inky 788 wrote: On Jul 23, 3:42 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: 8 Steven showed why you cannot have a mutable thing as a key in a dict. if you think it is contrived, then please consider how you would keep

Re: Help understanding the decisions *behind* python?

2009-07-24 Thread Beni Cherniavsky
On Jul 22, 9:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: My guess is that it was probably for optimization reasons long ago. I've never heard a *good* reason why Python needs both. The good reason is the immutability, which lets

Re: Help understanding the decisions *behind* python?

2009-07-24 Thread Inky 788
On Jul 23, 3:42 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Wednesday 22 July 2009 16:36:51 Inky 788 wrote: On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: The good reason is the immutability, which lets you use a tuple as a dict key.   Thanks for

Re: Help understanding the decisions *behind* python?

2009-07-24 Thread Uncle Roastie
On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: My colleagues and I have been working with python for around 6 months now, and while we love a lot of what python has done for us and what it enables us to do some of the decisions behind such certain data-types and their

Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Gabriel Genellina
En Wed, 22 Jul 2009 11:36:51 -0300, Inky 788 inky...@gmail.com escribió: On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: The good reason is the immutability, which lets you use a tuple as a dict key.   Thanks for the reply Hendrik (and Steven (other reply)). Perhaps

Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Hendrik van Rooyen
On Wednesday 22 July 2009 16:36:51 Inky 788 wrote: On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: The good reason is the immutability, which lets you use a tuple as a dict key.   Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm just not

Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Tim Rowe
2009/7/22 Inky 788 inky...@gmail.com: Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm just not sophisticated enough, but I've never wanted to use a list/ tuple as a dict key. This sounds like obscure usage, and a bit contrived as a reason for having *both* lists and

Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Mark Lawrence
Phillip B Oldham wrote: My colleagues and I have been working with python for around 6 months now, and while we love a lot of what python has done for us and what it enables us to do some of the decisions behind such certain data-types and their related methods baffle us slightly (when compared

Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Aahz
In article mailman.3616.1248369685.8015.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: Sorry if this has been discussed and I've missed it, but how about memory allocation. An immutable tuple has a fixed memory allocation whereas that for the mutable list must be liable

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Hendrik van Rooyen
On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Steven D'Aprano
On Tue, 21 Jul 2009 00:39:24 +0200, Niels L. Ellegaard wrote: Phillip B Oldham phillip.old...@gmail.com writes: We often find we need to do manipulations like the above without changing the order of the original list, and languages like JS allow this. We can't work out how to do this in

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Steven D'Aprano
On Tue, 21 Jul 2009 06:49:59 -0700, Inky 788 wrote: On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Duncan Booth
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: But that's the wrong solution to the problem. The OP wants the largest (or smallest) item, which he expects to get by sorting, then grabbing the first element: sorted(alist)[0] That requires sorting the entire list, only to

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Inky 788
On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Luis Alberto Zarrabeitia Gomez
Quoting Inky 788 inky...@gmail.com: The good reason is the immutability, which lets you use a tuple as a dict key.   Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm just not sophisticated enough, but I've never wanted to use a list/ tuple as a dict key. This sounds

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Hendrik van Rooyen
On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really? That

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Duncan Booth
Hrvoje Niksic hnik...@xemacs.org wrote: Chris Rebert c...@rebertia.com writes: x = [2,1,3] print sorted(x)[0] DB 3 What kind of Python produces that? Assuming you're referring to the latter example, it was added in version 2.4 If you meant the former example, I think that's purely

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Inky 788
On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very similar job as far as we can tell. My guess is that it

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Piet van Oostrum
Hendrik van Rooyen hend...@microcorp.co.za (HvR) wrote: HvR On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread David Smith
Piet van Oostrum wrote: Hendrik van Rooyen hend...@microcorp.co.za (HvR) wrote: HvR On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Piet van Oostrum
David Smith d...@cornell.edu (DS) wrote: DS Piet van Oostrum wrote: Hendrik van Rooyen hend...@microcorp.co.za (HvR) wrote: HvR On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both

Re: Help understanding the decisions *behind* python?

2009-07-21 Thread Simon Forman
On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: My colleagues and I have been working with python for around 6 months now, and while we love a lot of what python has done for us and what it enables us to do some of the decisions behind such certain data-types and their

Help understanding the decisions *behind* python?

2009-07-20 Thread Phillip B Oldham
My colleagues and I have been working with python for around 6 months now, and while we love a lot of what python has done for us and what it enables us to do some of the decisions behind such certain data-types and their related methods baffle us slightly (when compared to the decisions made in

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Tycho Andersen
On Mon, Jul 20, 2009 at 11:27 AM, Phillip B Oldhamphillip.old...@gmail.com wrote: snip We often find we need to do manipulations like the above without changing the order of the original list, and languages like JS allow this. We can't work out how to do this in python though, other than

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Duncan Booth
Phillip B Oldham phillip.old...@gmail.com wrote: This make a lot more sense to us, and follows the convention from other languages. It would also mean chaining methods to manipulate lists would be easier: x = [2,1,3] print x.sort()[0] 3 print x [2,1,3] You already have a way to do what

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Michiel Overtoom
Phillip wrote: Specifically the differences between lists and tuples have us confused and have caused many discussions in the office. We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Anthony Tolle
On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: ... Specifically the differences between lists and tuples have us confused and have caused many discussions in the office. We understand that lists are mutable and tuples are not, but we're a little lost as to why the two

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Phillip B Oldham
On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really? That sounds interesting, although I can't think of any real-

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Duncan Booth
Phillip B Oldham phillip.old...@gmail.com wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really? That sounds

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Marcus Wanner
On 7/20/2009 3:26 PM, Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really? That sounds

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread J. Cliff Dyer
On Mon, 2009-07-20 at 12:26 -0700, Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really?

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Piet van Oostrum
Duncan Booth duncan.bo...@invalid.invalid (DB) wrote: DB Phillip B Oldham phillip.old...@gmail.com wrote: This make a lot more sense to us, and follows the convention from other languages. It would also mean chaining methods to manipulate lists would be easier: x = [2,1,3] print

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Chris Rebert
On Mon, Jul 20, 2009 at 2:23 PM, Piet van Oostrump...@cs.uu.nl wrote: Duncan Booth duncan.bo...@invalid.invalid (DB) wrote: DB Phillip B Oldham phillip.old...@gmail.com wrote: This make a lot more sense to us, and follows the convention from other languages. It would also mean chaining methods

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Paul Moore
2009/7/20 Chris Rebert c...@rebertia.com: On Mon, Jul 20, 2009 at 2:23 PM, Piet van Oostrump...@cs.uu.nl wrote: x = [2,1,3] print sorted(x)[0] DB 3 What kind of Python produces that? Assuming you're referring to the latter example, it was added in version 2.4 If you meant the former

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Niels L. Ellegaard
Phillip B Oldham phillip.old...@gmail.com writes: We often find we need to do manipulations like the above without changing the order of the original list, and languages like JS allow this. We can't work out how to do this in python though, other than duplicating the list, sorting, reversing,

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Christian Heimes
Niels L. Ellegaard wrote: Phillip B Oldham phillip.old...@gmail.com writes: We often find we need to do manipulations like the above without changing the order of the original list, and languages like JS allow this. We can't work out how to do this in python though, other than duplicating

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Hrvoje Niksic
Phillip B Oldham phillip.old...@gmail.com writes: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really? That sounds

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Hrvoje Niksic
Chris Rebert c...@rebertia.com writes: x = [2,1,3] print sorted(x)[0] DB 3 What kind of Python produces that? Assuming you're referring to the latter example, it was added in version 2.4 If you meant the former example, I think that's purely pseudo-Python. sorted([2, 1, 3])[0] evaluates

Re: Help understanding the decisions *behind* python?

2009-07-20 Thread Piet van Oostrum
Paul Moore p.f.mo...@gmail.com (PM) wrote: PM 2009/7/20 Chris Rebert c...@rebertia.com: On Mon, Jul 20, 2009 at 2:23 PM, Piet van Oostrump...@cs.uu.nl wrote: x = [2,1,3] print sorted(x)[0] DB 3 What kind of Python produces that? Assuming you're referring to the latter example, it was