Re: ways to declare empty set variable

2008-02-16 Thread Steven D'Aprano
On Sat, 16 Feb 2008 11:14:10 -0500, Steve Holden wrote: > It's about four years since I wrote a program that ran for more than 24 > hours. Let me guess... and then you discovered ''.join(['x', 'y']) instead of 'x'+'y'? *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: ways to declare empty set variable

2008-02-16 Thread Steve Holden
Boris Borcic wrote: > Steve Holden wrote: [...] >> Before you have any code is exactly the *wrong* time to be considering >> performance. > > Yeah right, [] and {} are premature optimizations, one should always use > list() > or dict() unless one detains figures to justify the more exotic forms

Re: ways to declare empty set variable

2008-02-16 Thread Boris Borcic
Steve Holden wrote: > Boris Borcic wrote: >> [EMAIL PROTECTED] wrote: >>> ...Missing that, I think dict() and set() and >>> tuple() and list() look better than using {} for the empty dict and >>> {/} for the empty set and () for empty tuple (or {} for the empty dict >>> and set() for the empty set)

Re: ways to declare empty set variable

2008-02-16 Thread Steven D'Aprano
On Sat, 16 Feb 2008 05:21:22 -0500, Steve Holden wrote: > Before you have any code is exactly the *wrong* time to be considering > performance. Well, not really. Don't we already tell people "don't use repeated string concatenation, because it is slow", even *before* we know whether it is a bot

Re: ways to declare empty set variable

2008-02-16 Thread Steve Holden
Boris Borcic wrote: > [EMAIL PROTECTED] wrote: >> ...Missing that, I think dict() and set() and >> tuple() and list() look better than using {} for the empty dict and >> {/} for the empty set and () for empty tuple (or {} for the empty dict >> and set() for the empty set). > > The problem I have w

Re: ways to declare empty set variable

2008-02-16 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > > ...Missing that, I think dict() and set() and > tuple() and list() look better than using {} for the empty dict and > {/} for the empty set and () for empty tuple (or {} for the empty dict > and set() for the empty set). The problem I have with them is in no way the l

Re: ways to declare empty set variable

2008-02-13 Thread Steve Holden
[EMAIL PROTECTED] wrote: > The irony that, x = (,) produces an error. > > Personally I would of thought it would be a better example of an empty > tuple than anything else, but it still isn't that readable. > > The use of dict/list/tuple/set seems to stand out a lot better, makes > it readable! E

Re: ways to declare empty set variable

2008-02-13 Thread Ben Finney
Nick Craig-Wood <[EMAIL PROTECTED]> writes: > Ben Finney <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] writes: > > > > > Missing that, I think dict() and set() and tuple() and list() > > > > I often use these myself. They're slightly more explicit, which can > > help when I want the reader

Re: ways to declare empty set variable

2008-02-13 Thread Nick Craig-Wood
Ben Finney <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > > Missing that, I think dict() and set() and tuple() and list() > > I often use these myself. They're slightly more explicit, which can > help when I want the reader not to have to think too much, and they're > not particul

Re: ways to declare empty set variable

2008-02-13 Thread cokofreedom
The irony that, x = (,) produces an error. Personally I would of thought it would be a better example of an empty tuple than anything else, but it still isn't that readable. The use of dict/list/tuple/set seems to stand out a lot better, makes it readable! Else in a few years you'll have §x§ = !^

Re: ways to declare empty set variable

2008-02-12 Thread George Sakkis
On Feb 12, 9:30 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > George Sakkis <[EMAIL PROTECTED]> writes: > > On Feb 12, 7:02 pm, Ben Finney <[EMAIL PROTECTED]> > > wrote: > > > That makes it even more a violation of > > > principle-of-least-astonishment that the '(foo)' form doesn't give > > > a one-e

Re: ways to declare empty set variable

2008-02-12 Thread Ben Finney
George Sakkis <[EMAIL PROTECTED]> writes: > On Feb 12, 7:02 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: > > That makes it even more a violation of > > principle-of-least-astonishment that the '(foo)' form doesn't give > > a one-element tuple literal. > > The reason being, of course, that in this

Re: ways to declare empty set variable

2008-02-12 Thread George Sakkis
On Feb 12, 7:02 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > Steve Holden <[EMAIL PROTECTED]> writes: > > Ben Finney wrote: > > [...] > > > > Note that '()' is syntactically null. Parentheses don't declare a > > > tuple literal, commas do. Parentheses are for grouping within > > > expressions, not s

Re: ways to declare empty set variable

2008-02-12 Thread Ben Finney
[EMAIL PROTECTED] writes: > Ben Finney: > > Generator literals do not require the parens at all. However, the > > syntax of where the generator literal *appears* can make it > > necessary to explicitly group the expression using parens. > > Have you taken a look at Boo? > In Python this isn't pos

Re: ways to declare empty set variable

2008-02-12 Thread bearophileHUGS
Ben Finney: > Generator literals do not require the > parens at all. However, the syntax of where the generator literal > *appears* can make it necessary to explicitly group the expression > using parens. Have you taken a look at Boo? In Python this isn't possible: s = char for char in string.digi

Re: ways to declare empty set variable

2008-02-12 Thread Ben Finney
[EMAIL PROTECTED] writes: > In Python ( ) denote: > - expression grouping > - they are very often used to denote tuples (despite being necessary > only for the empty one) > - generators (x for x in ...). > The Boo language shows that () aren't that necessary for the > generators. Now, that one I

Re: ways to declare empty set variable

2008-02-12 Thread Ben Finney
Steve Holden <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > [...] > > > > Note that '()' is syntactically null. Parentheses don't declare a > > tuple literal, commas do. Parentheses are for grouping within > > expressions, not specifying type. > > > Tell that to the interpreter: > > >>> type((

Re: ways to declare empty set variable

2008-02-12 Thread Steve Holden
Ben Finney wrote: [...] > > Note that '()' is syntactically null. Parentheses don't declare a > tuple literal, commas do. Parentheses are for grouping within > expressions, not specifying type. > Tell that to the interpreter: >>> type(()) >>> tuple() is () True >>> regards Steve -- Steve

Re: ways to declare empty set variable

2008-02-12 Thread bearophileHUGS
Ben Finney: > I often use these myself. They're slightly more explicit, which can > help when I want the reader not to have to think too much, and they're > not particularly verbose because the names are well-chosen and short. I'd like "list" be called "array" ;-) > Note that '()' is syntactical

Re: ways to declare empty set variable

2008-02-12 Thread Ben Finney
[EMAIL PROTECTED] writes: > For Python 3.0 I'd like {} for the empty set and {:} for the empty > dict, but that idea was refused time ago, probably for some mental > backward compatibility. I agree with not breaking that backward compatibility; it seems wanton. > Missing that, I think dict() and

Re: ways to declare empty set variable

2008-02-12 Thread bearophileHUGS
Paul Rubin: > In 3.0 you may be able to say {,} but there is a contingent that would > just as soon get rid of all that special syntax, so you'd say list() > instead of [], dict() instead of {}, etc. For Python 3.0 I'd like {} for the empty set and {:} for the empty dict, but that idea was refused

Re: ways to declare empty set variable

2008-02-12 Thread Ben Finney
"Sun" <[EMAIL PROTECTED]> writes: > I was wondering why can't I use a format as "var = {} " to > "var=list()" in set variable, and decided not to bother with it. Python 3.0 will gain syntax to specify a literal of type 'set' http://www.python.org/dev/peps/pep-3100/>:: >>> {17, "foo", 12.5}

Re: ways to declare empty set variable

2008-02-12 Thread Paul Rubin
"Sun" <[EMAIL PROTECTED]> writes: > I was wondering why can't I use a format as "var = {} " to "var=list()" in > set variable, and decided not to bother with it. In 3.0 you may be able to say {,} but there is a contingent that would just as soon get rid of all that special syntax, so you'd say l

Re: ways to declare empty set variable

2008-02-12 Thread Gabriel Genellina
En Tue, 12 Feb 2008 12:04:43 -0200, Sun <[EMAIL PROTECTED]> escribió: > "Chris" <[EMAIL PROTECTED]> wrote > test = set() > test >> set([]) > > yeah, that 's what I am looking for, thanks all for such prompt answers! > > I was wondering why can't I use a format as "var = {} " to "var=list()

Re: ways to declare empty set variable

2008-02-12 Thread Sun
"Chris" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Feb 12, 3:45 pm, "Sun" <[EMAIL PROTECTED]> wrote: >> Maybe this is a very primative question, but I just get a bit confused >> about >> 'set' and 'Set' module in python. >> >> I understand 'set' is a build in type in python

Re: ways to declare empty set variable

2008-02-12 Thread Chris
On Feb 12, 3:45 pm, "Sun" <[EMAIL PROTECTED]> wrote: > Maybe this is a very primative question, but I just get a bit confused about > 'set' and 'Set' module in python. > > I understand 'set' is a build in type in python after 2.4(or 2.3) and Set a > seperate module, anyhow, I gonna use build in 'se

Re: ways to declare empty set variable

2008-02-12 Thread Marc 'BlackJack' Rintsch
On Tue, 12 Feb 2008 14:45:43 +0100, Sun wrote: > then the question is how can I declare a empty set variable as a 'var= []' > do to a list variable? You don't declare variables in Python. Just create an instance of `set` and bind it to a name: var = set() Ciao, Marc 'BlackJack' Rintsc

ways to declare empty set variable

2008-02-12 Thread Sun
Maybe this is a very primative question, but I just get a bit confused about 'set' and 'Set' module in python. I understand 'set' is a build in type in python after 2.4(or 2.3) and Set a seperate module, anyhow, I gonna use build in 'set'. then the question is how can I declare a empty set vari