Re: Why tuple with one item is no tuple

2005-03-29 Thread Antoon Pardon
Op 2005-03-27, Joal Heagney schreef [EMAIL PROTECTED]: Antoon Pardon wrote: snip So python choose a non-deterministic direction. To me (2,3) + (4,5) equals (6,8). I don't dispute that having an operator to combine (2,3) and (4,5) in (2,3,4,5) is usefull, but they should never have used the +

Re: Why tuple with one item is no tuple

2005-03-29 Thread Ville Vainio
Antoon == Antoon Pardon [EMAIL PROTECTED] writes: Antoon Op 2005-03-27, Joal Heagney schreef [EMAIL PROTECTED]: Antoon Pardon wrote: snip So python choose a non-deterministic direction. To me (2,3) + (4,5) equals (6,8). I don't dispute that having an operator to combine

Re: Why tuple with one item is no tuple

2005-03-29 Thread Ville Vainio
Ville == Ville Vainio [EMAIL PROTECTED] writes: Ville To me, nothing is more natural than ab + cd == Ville abcd. Also [1,2] + [3,4] == [1,2,3,4]. Dot product is Ville not really too useful in real world (non-mathematical) Ville apps. ... and of course by dot product, I don't

Re: Why tuple with one item is no tuple

2005-03-29 Thread Antoon Pardon
Op 2005-03-29, Ville Vainio schreef [EMAIL PROTECTED]: Antoon == Antoon Pardon [EMAIL PROTECTED] writes: Antoon Op 2005-03-27, Joal Heagney schreef [EMAIL PROTECTED]: Antoon Pardon wrote: snip So python choose a non-deterministic direction. To me (2,3) + (4,5) equals

Re: Why tuple with one item is no tuple

2005-03-26 Thread Joal Heagney
Antoon Pardon wrote: snip So python choose a non-deterministic direction. To me (2,3) + (4,5) equals (6,8). I don't dispute that having an operator to combine (2,3) and (4,5) in (2,3,4,5) is usefull, but they should never have used the + for that. (alph, bravo) + (delta, max) -- (alphdelta,

Re: Why tuple with one item is no tuple

2005-03-22 Thread TZOTZIOY
On 15 Mar 2005 11:25:15 -0500, rumours say that [EMAIL PROTECTED] (Roy Smith) might have written: The big question is, is it the parens that make it a tuple, or is it the comma? If you go along with the parens school of thought, then (1,) is the special case. If you believe in commas, then the

Re: Why tuple with one item is no tuple

2005-03-18 Thread Kay Schluehr
Antoon Pardon wrote: for instance I have written once somekind of vector class where it was natural for these vectors to be added as well as te be concatenated. Unfortunately python uses + for both so I had no way to have both operators in a natural way in python. Yes this is a quite common

Re: Why tuple with one item is no tuple

2005-03-18 Thread Antoon Pardon
Op 2005-03-17, Diez B. Roggisch schreef [EMAIL PROTECTED]: So python choose a non-deterministic direction. To me (2,3) + (4,5) equals (6,8). I don't dispute that having an operator to combine (2,3) and (4,5) in (2,3,4,5) is usefull, but they should never have used the + for that. It

Re: Why tuple with one item is no tuple

2005-03-18 Thread Antoon Pardon
Op 2005-03-16, Daniel Dittmar schreef [EMAIL PROTECTED]: Diez B. Roggisch wrote: I reread his example and have to admit I'm confused: He complains about having written his _own_ vector class - and concatenation and addition had to use both + ? I've interpreted it as: If Python had choosen

Re: Why tuple with one item is no tuple

2005-03-18 Thread Daniel Dittmar
Antoon Pardon wrote: My peeve is about having operators added to standard types. This increases the chances that using an object the wrong way leads to a bogus result, not a runtime error. A more common programming error I commit is passing a string where a list ist expected. And then I wonder

Re: Why tuple with one item is no tuple

2005-03-18 Thread Antoon Pardon
Op 2005-03-18, Daniel Dittmar schreef [EMAIL PROTECTED]: Antoon Pardon wrote: My peeve is about having operators added to standard types. This increases the chances that using an object the wrong way leads to a bogus result, not a runtime error. A more common programming error I commit is

Re: Why tuple with one item is no tuple

2005-03-18 Thread Steven Bethard
Kay Schluehr wrote: On the other hand i find Mathematicas list operators very appealing: In =: [1,2,3]^2 Out=: [1,4,9] Compared with this suggar the list comprehension [x**2 for x in [1,2,3]] is ugly. py import numarray py a = numarray.array([1, 2, 3]) py a**2 array([1, 4, 9]) STeVe --

Re: Why tuple with one item is no tuple

2005-03-17 Thread Antoon Pardon
Op 2005-03-16, Diez B. Roggisch schreef [EMAIL PROTECTED]: That ambiguity is only caused because python uses the same characters for very different operations and to be honest I don't like that. As I said: show me which parentheses to use - and keep in mind that: - and are for

Re: Why tuple with one item is no tuple

2005-03-17 Thread Diez B. Roggisch
So python choose a non-deterministic direction. To me (2,3) + (4,5) equals (6,8). I don't dispute that having an operator to combine (2,3) and (4,5) in (2,3,4,5) is usefull, but they should never have used the + for that. It certainly did not choose a nondeterministic action - that would mean

Re: Why tuple with one item is no tuple

2005-03-16 Thread Tim Roberts
Gregor Horvath [EMAIL PROTECTED] wrote: type(['1']) type 'list' type(('1')) type 'str' I wonder why ('1') is no tuple There were lots of answers, but I'm not sure I saw the why addressed. Consider this: a = (3 + 5) * 5 You really, really want (3 + 5) to be an integer, not a

Re: Why tuple with one item is no tuple

2005-03-16 Thread Antoon Pardon
Op 2005-03-16, Tim Roberts schreef [EMAIL PROTECTED]: Gregor Horvath [EMAIL PROTECTED] wrote: type(['1']) type 'list' type(('1')) type 'str' I wonder why ('1') is no tuple There were lots of answers, but I'm not sure I saw the why addressed. Consider this: a = (3 + 5) * 5 You

Re: Why tuple with one item is no tuple

2005-03-16 Thread Diez B. Roggisch
Consider this:  a = (3 + 5) * 5 You really, really want (3 + 5) to be an integer, not a one-item tuple. I sometimes do wonder if some impliciteness wouldn't be better here, so that any item could be treated as if it was a one-item tuple. A bit like every char being a string. There

Re: Why tuple with one item is no tuple

2005-03-16 Thread Antoon Pardon
Op 2005-03-16, Diez B. Roggisch schreef [EMAIL PROTECTED]: Consider this:  a = (3 + 5) * 5 You really, really want (3 + 5) to be an integer, not a one-item tuple. I sometimes do wonder if some impliciteness wouldn't be better here, so that any item could be treated as if it was a

Re: Why tuple with one item is no tuple

2005-03-16 Thread Diez B. Roggisch
That ambiguity is only caused because python uses the same characters for very different operations and to be honest I don't like that. As I said: show me which parentheses to use - and keep in mind that: - and are for comparisions and the same ambiguity troubles arise - unicode surely

Re: Why tuple with one item is no tuple

2005-03-16 Thread Daniel Dittmar
Diez B. Roggisch wrote: for instance I have written once somekind of vector class where it was natural for these vectors to be added as well as te be concatenated. Unfortunately python uses + for both so I had no way to have both operators in a natural way in python. And no way in mathematics or

Re: Why tuple with one item is no tuple

2005-03-16 Thread Steven Bethard
Daniel Dittmar wrote: But what the heck, I find list comprehension rather awful. Sacrilege! ;) STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: Why tuple with one item is no tuple

2005-03-16 Thread Diez B. Roggisch
I think he meant that Python should have introduced different operators for addition and sequence concatenation. I reread his example and have to admit I'm confused: He complains about having written his _own_ vector class - and concatenation and addition had to use both + ? He could have used

Re: Why tuple with one item is no tuple

2005-03-16 Thread Daniel Dittmar
Diez B. Roggisch wrote: I reread his example and have to admit I'm confused: He complains about having written his _own_ vector class - and concatenation and addition had to use both + ? I've interpreted it as: If Python had choosen different operators for addition and sequence concatenation, I

Re: Why tuple with one item is no tuple

2005-03-16 Thread James Stroud
On Wednesday 16 March 2005 07:22 am, Diez B. Roggisch wrote: As I said: show me which parentheses to use I kind of like the comma as a tuple parentheses ,1,2,3, replacing (1,2,3) or 1,2,3, or 1,2,3 or (isn't this is getting out of hand?) (1,2,3,) Why not--except of course for backward

Re: Why tuple with one item is no tuple

2005-03-16 Thread Robert Kern
James Stroud wrote: On Wednesday 16 March 2005 07:22 am, Diez B. Roggisch wrote: As I said: show me which parentheses to use I kind of like the comma as a tuple parentheses ,1,2,3, replacing (1,2,3) or 1,2,3, or 1,2,3 or (isn't this is getting out of hand?) (1,2,3,) Why not--except of course for

Re: Why tuple with one item is no tuple

2005-03-16 Thread James Stroud
On Wednesday 16 March 2005 04:45 pm, Robert Kern wrote: This would be very unambiguous. Not entirely. Then, the purity would manifest itself the naked comma being an empty tuple. Think about the zen of:    , Is that a tuple or grit on my monitor?  :-) OK, OK, I'll give up on the

Re: Why tuple with one item is no tuple

2005-03-16 Thread Jeremy Bowers
On Wed, 16 Mar 2005 17:28:51 -0800, James Stroud wrote: On Wednesday 16 March 2005 04:45 pm, Robert Kern wrote: This would be very unambiguous. Not entirely. Then, the purity would manifest itself the naked comma being an empty tuple. Think about the zen of: , Is that a tuple or

Why tuple with one item is no tuple

2005-03-15 Thread Gregor Horvath
Hi, type(['1']) type 'list' type(('1')) type 'str' I wonder why ('1') is no tuple Because I have to treat this special case differently in my code. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Why tuple with one item is no tuple

2005-03-15 Thread Fuzzyman
('1',) is a tuple... you need the comma to make it a tuple. regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list

RE: Why tuple with one item is no tuple

2005-03-15 Thread Batista, Facundo
Title: RE: Why tuple with one item is no tuple [Gregor Horvath] #- type(('1')) #- type 'str' #- #- I wonder why ('1') is no tuple The parentheses don't create the tuple, the comma does: ('1') '1' ('1',) ('1',) '1', ('1',) . Facundo Bitácora De Vuelo: http

Re: Why tuple with one item is no tuple

2005-03-15 Thread Bill Mill
On Tue, 15 Mar 2005 16:16:34 GMT, Gregor Horvath [EMAIL PROTECTED] wrote: Hi, type(['1']) type 'list' type(('1')) type 'str' I wonder why ('1') is no tuple because, syntactically, those parens are for grouping, and do not unambiguously define a tuple. It's a python gotcha. To

Re: Why tuple with one item is no tuple

2005-03-15 Thread deelan
Gregor Horvath wrote: Hi, type(['1']) type 'list' type(('1')) type 'str' I wonder why ('1') is no tuple Because I have to treat this special case differently in my code. you need to tell python that ('1') isn't a string inside a couple parens but a tuple, look: t = ('1', ) type(t) type

Re: Why tuple with one item is no tuple

2005-03-15 Thread Roy Smith
Gregor Horvath [EMAIL PROTECTED] wrote: Hi, type(['1']) type 'list' type(('1')) type 'str' I wonder why ('1') is no tuple You need to say ('1',). In just plain ('1'), the parens are interpreted as grouping, not as tuple creation. Depending on your point of view, this is either a

Re: Why tuple with one item is no tuple

2005-03-15 Thread Gregor Horvath
thanks are given to all problem solved... -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Why tuple with one item is no tuple

2005-03-15 Thread Paddy
Hmm, going 'the other way', you are allowed an extra , but you can't have (,) as the empty tuple.: (1,2,) (1, 2) (1,) (1,) (,) ... Traceback ( File interactive input, line 1 (,) ^ SyntaxError: invalid syntax -- Pad. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why tuple with one item is no tuple

2005-03-15 Thread James Stroud
On Tuesday 15 March 2005 08:25 am, Roy Smith wrote: a = ()       # tuple of zero elements a = (1,)     # tuple of one element a = 1,       # tuple of one element a = (1)      # scalar a = (1, 2)   # tuple of two elements a = 1, 2     # tuple of two elements a = ,        # syntax error The

Re: Why tuple with one item is no tuple

2005-03-15 Thread Bill Mill
On Tue, 15 Mar 2005 10:47:28 -0800, James Stroud [EMAIL PROTECTED] wrote: On Tuesday 15 March 2005 08:25 am, Roy Smith wrote: a = () # tuple of zero elements a = (1,) # tuple of one element a = 1, # tuple of one element a = (1) # scalar a = (1, 2) # tuple of two

Re: Why tuple with one item is no tuple

2005-03-15 Thread Reinhold Birkenfeld
Bill Mill wrote: On Tue, 15 Mar 2005 10:47:28 -0800, James Stroud [EMAIL PROTECTED] wrote: On Tuesday 15 March 2005 08:25 am, Roy Smith wrote: a = () # tuple of zero elements a = (1,) # tuple of one element a = 1, # tuple of one element a = (1) # scalar a = (1, 2)

Re: Why tuple with one item is no tuple

2005-03-15 Thread Max M
Gregor Horvath wrote: thanks are given to all problem solved... Personally I add a , after every list/tuple item. Also the last. It also makes copy/pasting code easier. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list