Re: length of a tuple or a list containing only one element

2009-01-07 Thread Glenn Linderman
On approximately 11/3/2008 11:55 AM, came the following characters from the keyboard of Tim Chase: For making a literal tuple, parentheses are irrelevant; only the commas matter: I don't think I'd go so far as to say that the parentheses around tuples are *irrelevant*...maybe just relevant in se

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Tim Chase
For making a literal tuple, parentheses are irrelevant; only the commas matter: I don't think I'd go so far as to say that the parentheses around tuples are *irrelevant*...maybe just relevant in select contexts >>> def foo(*args): ... for i, arg in enumerate(args): ... print

Re: length of a tuple or a list containing only one element

2008-11-03 Thread bearophileHUGS
Arnaud Delobelle: >And introduces some new inconsistencies for newcomers, e.g. > s = {1, 2, 3} # A set with 3 elements > s = {1} # A set with one element > s = {} # Surely, this should be an empty set!! Are you able to list other inconsistencies? Python3 introduces one or two warts, but removes

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > Steve Holden: >> While this kind of beginner >> mistake is common it isn't one that's frequently repeated once the >> learner understands the syntax. > > You may be right, but I don't have to like it. > When you teach programming to people that have never done it before

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Scott David Daniels
Tim Chase wrote: For making a literal tuple, parentheses are irrelevant; only the commas matter: I don't think I'd go so far as to say that the parentheses around tuples are *irrelevant*...maybe just relevant in select contexts >>> def foo(*args): ... for i, arg in enumerate(args): ..

Re: length of a tuple or a list containing only one element

2008-11-03 Thread bearophileHUGS
Steve Holden: > While this kind of beginner > mistake is common it isn't one that's frequently repeated once the > learner understands the syntax. You may be right, but I don't have to like it. When you teach programming to people that have never done it before, and you use Python, they spot simil

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Steve Holden
[EMAIL PROTECTED] wrote: [...] > Where OR, AND, XOR, NOT, SHL, SHR are the bitwise operators. > Having to type (| |) often is less handy, for example this code: Which is precisely why bare parentheses are used. And remember, you often don't need to put the parentheses in. While this kind of beginn

Re: length of a tuple or a list containing only one element

2008-11-03 Thread bearophileHUGS
TP: > This is actually the length of a bracketed string, not a tuple. > Tuple's are defined by the existence of a comma...try: > >>> len(('foo',)) > 1 Time ago I have suggested to change the tuple literal, to avoid the warts of the singleton and empty tuple, that may lead to bugs. But using ASCII

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Tim Chase
For making a literal tuple, parentheses are irrelevant; only the commas matter: I don't think I'd go so far as to say that the parentheses around tuples are *irrelevant*...maybe just relevant in select contexts >>> def foo(*args): ... for i, arg in enumerate(args): ... prin

Re: length of a tuple or a list containing only one element

2008-11-03 Thread Ben Finney
TP <[EMAIL PROTECTED]> writes: > Hi everybody, > > I have a question about the difference of behavior of "len" when > applied on tuples or on lists. I mean: > > $ len( ( 'foo', 'bar' ) ) > 2 > $ len( ( 'foo' ) ) > 3 > $ len( [ 'foo', 'bar' ] ) > 2 > $ len( [ 'foo' ] ) > 1 For making a literal t

Re: length of a tuple or a list containing only one element

2008-11-03 Thread alex23
On Nov 3, 9:08 pm, TP <[EMAIL PROTECTED]> wrote: > I have a question about the difference of behavior of "len" when applied on > tuples or on lists. I mean: > $ len( ( 'foo' ) ) > 3 This is actually the length of a bracketed string, not a tuple. Tuple's are defined by the existence of a comma...tr

length of a tuple or a list containing only one element

2008-11-03 Thread TP
Hi everybody, I have a question about the difference of behavior of "len" when applied on tuples or on lists. I mean: $ len( ( 'foo', 'bar' ) ) 2 $ len( ( 'foo' ) ) 3 $ len( [ 'foo', 'bar' ] ) 2 $ len( [ 'foo' ] ) 1 Why this behavior for the length computation of a tuple? For my application, I p