Re: Addressing the last element of a list

2005-11-17 Thread Antoon Pardon
Op 2005-11-16, Mike Meyer schreef [EMAIL PROTECTED]: Antoon Pardon [EMAIL PROTECTED] writes: Op 2005-11-15, Mike Meyer schreef [EMAIL PROTECTED]: Antoon Pardon [EMAIL PROTECTED] writes: Like having an assignment operator (let use @= for it) next to a (re)bind operator. We could then have

Re: Addressing the last element of a list

2005-11-16 Thread Antoon Pardon
Op 2005-11-15, Bengt Richter schreef [EMAIL PROTECTED]: On 15 Nov 2005 08:51:59 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-11-14, Bengt Richter schreef [EMAIL PROTECTED]: [...] You may be interested in reviewing

Re: Addressing the last element of a list

2005-11-16 Thread Antoon Pardon
Op 2005-11-15, Mike Meyer schreef [EMAIL PROTECTED]: Antoon Pardon [EMAIL PROTECTED] writes: Like having an assignment operator (let use @= for it) next to a (re)bind operator. We could then have something like the following. a = 5 b = a a @= 7 b == would result in 7. You've just

Re: Addressing the last element of a list

2005-11-16 Thread Mike Meyer
Antoon Pardon [EMAIL PROTECTED] writes: Op 2005-11-15, Mike Meyer schreef [EMAIL PROTECTED]: Antoon Pardon [EMAIL PROTECTED] writes: Like having an assignment operator (let use @= for it) next to a (re)bind operator. We could then have something like the following. a = 5 b = a a @= 7 b ==

Re: Addressing the last element of a list

2005-11-15 Thread Antoon Pardon
Op 2005-11-14, Mike Meyer schreef [EMAIL PROTECTED]: Antoon Pardon [EMAIL PROTECTED] writes: Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]: [Context recovered from top posting.] [EMAIL PROTECTED] [EMAIL PROTECTED] writes: Daniel Crespo wrote: Well, I hope that newcomers to Python don't

Re: Addressing the last element of a list

2005-11-15 Thread Antoon Pardon
Op 2005-11-14, Bengt Richter schreef [EMAIL PROTECTED]: On 14 Nov 2005 11:20:53 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-11-14, Paul Rubin schreef http: Antoon Pardon [EMAIL PROTECTED] writes: We could then have something like the following. a = 5 b = a a @= 7 b == would

Re: Addressing the last element of a list

2005-11-15 Thread Chris Mellon
On 11/14/05, Bengt Richter [EMAIL PROTECTED] wrote: On 14 Nov 2005 11:20:53 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-11-14, Paul Rubin schreef http: Antoon Pardon [EMAIL PROTECTED] writes: We could then have something like the following. a = 5 b = a a @= 7 b == would

Re: Addressing the last element of a list

2005-11-15 Thread Bengt Richter
On 15 Nov 2005 08:51:59 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-11-14, Bengt Richter schreef [EMAIL PROTECTED]: [...] You may be interested in reviewing http://groups.google.com/group/comp.lang.python/browse_thread/thread/f96b496b6ef14e2/32d3539e928986b3 before continuing

Re: Addressing the last element of a list

2005-11-15 Thread Bengt Richter
On Tue, 15 Nov 2005 03:23:11 -0600, Chris Mellon [EMAIL PROTECTED] wrote: On 11/14/05, Bengt Richter [EMAIL PROTECTED] wrote: [...] You may be interested in reviewing http://groups.google.com/group/comp.lang.python/browse_thread/thread/= f96b496b6ef14e2/32d3539e928986b3 before continuing

Re: Addressing the last element of a list

2005-11-15 Thread Mike Meyer
Antoon Pardon [EMAIL PROTECTED] writes: Like having an assignment operator (let use @= for it) next to a (re)bind operator. We could then have something like the following. a = 5 b = a a @= 7 b == would result in 7. You've just overwritten the object referred to by the token 5 in the

Re: Addressing the last element of a list

2005-11-14 Thread Antoon Pardon
Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]: [Context recovered from top posting.] [EMAIL PROTECTED] [EMAIL PROTECTED] writes: Daniel Crespo wrote: Well, I hope that newcomers to Python don't confuse himselves :) This mutable/immutable object and name/variable is confusing. Only if

Re: Addressing the last element of a list

2005-11-14 Thread Paul Rubin
Antoon Pardon [EMAIL PROTECTED] writes: We could then have something like the following. a = 5 b = a a @= 7 b == would result in 7. Ouch! :-((( Can't you live with a = [5] b = a a[0] = 7 so b[0] is now 7. -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-14 Thread Antoon Pardon
Op 2005-11-14, Paul Rubin schreef http: Antoon Pardon [EMAIL PROTECTED] writes: We could then have something like the following. a = 5 b = a a @= 7 b == would result in 7. Ouch! :-((( Can't you live with a = [5] b = a a[0] = 7 so b[0] is now 7. And what do I have to do, in case

Re: Addressing the last element of a list

2005-11-14 Thread Mike Meyer
Antoon Pardon [EMAIL PROTECTED] writes: Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]: [Context recovered from top posting.] [EMAIL PROTECTED] [EMAIL PROTECTED] writes: Daniel Crespo wrote: Well, I hope that newcomers to Python don't confuse himselves :) This mutable/immutable object

Re: Addressing the last element of a list

2005-11-14 Thread Bengt Richter
On 14 Nov 2005 11:20:53 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Op 2005-11-14, Paul Rubin schreef http: Antoon Pardon [EMAIL PROTECTED] writes: We could then have something like the following. a = 5 b = a a @= 7 b == would result in 7. Ouch! :-((( Can't you live with a = [5] b

Re: Addressing the last element of a list

2005-11-14 Thread [EMAIL PROTECTED]
Bengt Richter wrote: You may be interested in reviewing http://groups.google.com/group/comp.lang.python/browse_thread/thread/f96b496b6ef14e2/32d3539e928986b3 before continuing this topic ;-) Interesting indeed, I mean the argument of why python does it this way. I see the equivalent

Re: Addressing the last element of a list

2005-11-14 Thread Bengt Richter
On Mon, 14 Nov 2005 09:53:34 -0500, Mike Meyer [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] writes: Op 2005-11-10, Mike Meyer schreef [EMAIL PROTECTED]: [Context recovered from top posting.] [EMAIL PROTECTED] [EMAIL PROTECTED] writes: Daniel Crespo wrote: Well, I hope that

Re: Addressing the last element of a list

2005-11-10 Thread Steven D'Aprano
On Thu, 10 Nov 2005 06:47:41 +, Donn Cave wrote: Quoth Steven D'Aprano [EMAIL PROTECTED]: ... | So when working with ints, strs or other immutable objects, you aren't | modifying the objects in place, you are rebinding the name to another | object: | | py spam = a tasty meat-like food

Re: Addressing the last element of a list

2005-11-10 Thread Antoon Pardon
Op 2005-11-10, Steven D'Aprano schreef [EMAIL PROTECTED]: On Thu, 10 Nov 2005 06:47:41 +, Donn Cave wrote: Quoth Steven D'Aprano [EMAIL PROTECTED]: ... | So when working with ints, strs or other immutable objects, you aren't | modifying the objects in place, you are rebinding the name to

Re: Addressing the last element of a list

2005-11-10 Thread Peter Otten
Antoon Pardon wrote: Write somekind of property so that if you manipulate a.x it would manipulate data[-1] Like that? def make_prp(index): ... def get(self): return self[index] ... def set(self, value): self[index] = value ... return property(get, set) ... class List(list): ...

Re: Addressing the last element of a list

2005-11-10 Thread Daniel Crespo
Hi Proposition 1: data = [0, None, 2, 0] ref = data[-1] ref = 1 assert data[-1] == 1 Logically, it doesn't work. Here you are assigning to ref a NEW value. That won't replace the data[-1] value. It's out of logic this proposition. While this (proposition 2): data = [0, None, 2, [hello]] ref

Re: Addressing the last element of a list

2005-11-10 Thread [EMAIL PROTECTED]
This mutable/immutable object and name/variable is confusing. Daniel Crespo wrote: Well, I hope that newcomers to Python don't confuse himselves :) Daniel -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-10 Thread Mike Meyer
[Context recovered from top posting.] [EMAIL PROTECTED] [EMAIL PROTECTED] writes: Daniel Crespo wrote: Well, I hope that newcomers to Python don't confuse himselves :) This mutable/immutable object and name/variable is confusing. Only if you have to overcome a conviction that variables behave

Re: Addressing the last element of a list

2005-11-10 Thread [EMAIL PROTECTED]
After one knows the characteristic, it is no problem. But judging from the frequency of the same issue coming up from time to time, it does confuse people coming from certain programming background. Mike Meyer wrote: Only if you have to overcome a conviction that variables behave in a different

Re: Addressing the last element of a list

2005-11-10 Thread Donn Cave
In article [EMAIL PROTECTED], Mike Meyer [EMAIL PROTECTED] wrote: ... Most OO languages do the name/variable thing, but some of the popular ones aren't consistent about it, giving some types special status, so that sometimes a = b causes b to be copied onto a, and sometimes it causes a to

Re: Addressing the last element of a list

2005-11-10 Thread Steven D'Aprano
On Thu, 10 Nov 2005 08:19:36 -0800, [EMAIL PROTECTED] wrote: This mutable/immutable object and name/variable is confusing. It is a source of confusion to newbies, because it is a distinction that may not be intuitively obvious, and it is a programming model that isn't quite the same as many

Re: Addressing the last element of a list

2005-11-09 Thread Donn Cave
Quoth Steven D'Aprano [EMAIL PROTECTED]: ... | So when working with ints, strs or other immutable objects, you aren't | modifying the objects in place, you are rebinding the name to another | object: | | py spam = a tasty meat-like food | py alias = spam # both names point to the same str object

Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
Isn't there an easier way than lst[len(lst) - 1] = ... ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
Or alternatively: Is there a way to make reference to the last element of a list, to use as a shorthand: ref := lst[len(lst) - 1] # I know syntax is wrong, but you get the idea and then using the last element of the list by (assuming the element is a dict): ref[foo] = 42 ref[bar] = Ni! etc.

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
I knew there was an easy way :) Just to satisfy my curiousity: Is there a way to do something like the reference solution I suggest above? -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Andreas Lobinger
Aloha, [EMAIL PROTECTED] wrote: Isn't there an easier way than lst[len(lst) - 1] = ... lst[-1] = ... Wishing a happy day LOBI -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
[EMAIL PROTECTED] wrote: Just to satisfy my curiousity: Is there a way to do something like the reference solution I suggest above? No. You cannot overload assignment. Of course, for mutable objects you can use the object as the reference to itself. Peter --

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
what do you mean by alias ? a = b now both a and b refers to the same object. [EMAIL PROTECTED] wrote: So there is no way in Python to make an alias for an object? /David -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
I just want an alias. Ideally, I don't want to deal with pointers or special reference types etc. After all, this is not C++ :) I just want to be able to make a reference to any old thing in Python. A list, an integer variable, a function etc. so that I, in complicated cases, can make a

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
But if lst[42][pos] happens to hold an integer value, then a = lst[42][pos] will _copy_ that integer value into 'a', right? Changing 'a' will not change the value at lst[42][pos] -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Bengt Richter
On 8 Nov 2005 01:12:07 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I knew there was an easy way :) Just to satisfy my curiousity: Is there a way to do something like the reference solution I suggest above? If the last element in the list was a dict, then you could do something like

Re: Addressing the last element of a list

2005-11-08 Thread Jerzy Karczmarczuk
Peter Otten wrote: [EMAIL PROTECTED] wrote: Just to satisfy my curiousity: Is there a way to do something like the reference solution I suggest above? No. You cannot overload assignment. I have the impression that this is not an issue, to overload assignments, which btw. *can* be

Re: Addressing the last element of a list

2005-11-08 Thread Bengt Richter
On 8 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: But if lst[42][pos] happens to hold an integer value, then a = lst[42][pos] will _copy_ that integer value into 'a', right? Changing 'a' will not change the value at lst[42][pos] Right, but try an example: lst =

Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
Jerzy Karczmarczuk wrote: Peter Otten wrote: [EMAIL PROTECTED] wrote: Just to satisfy my curiousity: Is there a way to do something like the reference solution I suggest above? No. You cannot overload assignment. I have the impression that this is not an issue, to overload

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
If you want to do what you want(though I don't know why without a concrete example), just store a mutable object at lst[42][pos], like this : lst[42][pos] = [1] a = lst[42][pos] a[0] = 2 assert(lst[42][pos][0] == 2) [EMAIL PROTECTED] wrote: But if lst[42][pos] happens to hold an integer value,

Re: Addressing the last element of a list

2005-11-08 Thread Simon Brunning
On 8 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: But if lst[42][pos] happens to hold an integer value, then a = lst[42][pos] will _copy_ that integer value into 'a', right? Nope. It will bind the name 'a' to the integer object. Changing 'a' will not change the

Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
[EMAIL PROTECTED] wrote: I just want an alias. Ideally, I don't want to deal with pointers or special reference types etc. After all, this is not C++ :) I just want to be able to make a reference to any old thing in Python. A list, an integer variable, a function etc. so that I, in

Re: Addressing the last element of a list

2005-11-08 Thread Jerzy Karczmarczuk
Peter Otten wrote cites me: I have the impression that this is not an issue, to overload assignments, which btw. *can* be overloaded, but the absence of *aliasing* (undiscriminate handling of pointers) in Python. Am I wrong? I think so. a = b will always make a a reference to (the same

Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
So there is no way in Python to make an alias for an object? /David -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Matt Hammond
On Tue, 08 Nov 2005 10:25:21 -, Jerzy Karczmarczuk [EMAIL PROTECTED] wrote: Would you please concentrate on - what I underlined - the sense of C aliasing, where you can make a pointer to point to anything, say, the 176th byte of a function code? Pretty much everything is referred

Re: Addressing the last element of a list

2005-11-08 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote: I just want an alias. What you want is impossible. But there are many workarounds. I just want to be able to make a reference to any old thing in Python. A list, an integer variable, a function etc. so that I, in complicated cases, can make a shorthand. If myRef

Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
Jerzy Karczmarczuk wrote: Sure, I didn't want to claim that the assignment a=anything can be plainly overloaded. I interpreted your previous post as such a claim. No disagreement here then. Would you please concentrate on - what I underlined - the sense of C aliasing, where you can make a

Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
On Tue, 08 Nov 2005 01:31:31 -0800, [EMAIL PROTECTED] wrote: So there is no way in Python to make an alias for an object? Yes, sort of. Bind two names to the same mutable object: py x = [Something mutable] py y = x py y.append(this way comes.) py print x ['Something mutable', 'this way

Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
On Tue, 08 Nov 2005 01:04:13 -0800, [EMAIL PROTECTED] wrote: Or alternatively: Is there a way to make reference to the last element of a list, to use as a shorthand: ref := lst[len(lst) - 1] # I know syntax is wrong, but you get the idea and then using the last element of the list by

Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
On Tue, 08 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED] wrote: But if lst[42][pos] happens to hold an integer value, then a = lst[42][pos] will _copy_ that integer value into 'a', right? Changing 'a' will not change the value at lst[42][pos] Not quite. Don't think of Python names as being

Re: Addressing the last element of a list

2005-11-08 Thread Michael
[EMAIL PROTECTED] wrote: Is there a way to make reference to the last element of a list, to use as a shorthand: Yes. It's not wise to use, since this is brittle and will fail hard for you, but since you're interested, this is how you /could/ do it: (largely) # First of all create a mechanism