Re: [Python-3000] Set literal

2008-02-03 Thread Greg Ewing
Larry Hastings wrote: > When compiling a mutable type with an immutable equivalent, does Python > generate create-empty-object/insert-each-item bytecodes, or does it > create an immutable constant then cast it to the appropriate type? Last time I looked, for lists and dicts it creates an empty o

Re: [Python-3000] Set literal

2008-02-03 Thread Larry Hastings
Nicko van Someren wrote: Do we really want set literals at all, given that set(...) exists? If we are going to have one then, it seems to make sense to have both. If we are going to have both, I would rather that they generate the same type of set. Maybe the postings crossed in the ether

Re: [Python-3000] Set literal

2008-02-02 Thread Stephen J. Turnbull
Greg Ewing writes: > But list(genexp) gives you very nearly the same thing [as a list > comprehension] -- so near that I find it hard to imagine anyone > would have thought to suggest a dedicated LC syntax if genexps had > already been present in the language. Point taken, except that I find

Re: [Python-3000] Set literal

2008-02-02 Thread Greg Ewing
Georg Brandl wrote: > Hm, but wouldn't he then have removed list comprehensions > by now using the time machine? I seem to remember that LCs were being seriously considered for removal in 3.x at one point. I'm not sure of all the reasons why they were kept. -- Greg ___

Re: [Python-3000] Set literal

2008-02-02 Thread Georg Brandl
Greg Ewing schrieb: > Stephen J. Turnbull wrote: >> Greg Ewing writes: >> >> > Also, if generator expressions had come first, we >> > would probably never have gotten list comprehensions. >> >> I don't understand. A list comprehension is for when you know you're >> going to want to work with t

Re: [Python-3000] Set literal

2008-02-02 Thread Greg Ewing
Stephen J. Turnbull wrote: > Greg Ewing writes: > > > Also, if generator expressions had come first, we > > would probably never have gotten list comprehensions. > > I don't understand. A list comprehension is for when you know you're > going to want to work with the whole list. But list(gene

Re: [Python-3000] Set literal

2008-02-02 Thread Andrew McNabb
On Sat, Feb 02, 2008 at 11:16:16AM +0900, Stephen J. Turnbull wrote: > Greg Ewing writes: > > > Also, if generator expressions had come first, we > > would probably never have gotten list comprehensions. > > I don't understand. A list comprehension is for when you know you're > going to want t

Re: [Python-3000] Set literal

2008-02-01 Thread Stephen J. Turnbull
Greg Ewing writes: > Also, if generator expressions had come first, we > would probably never have gotten list comprehensions. I don't understand. A list comprehension is for when you know you're going to want to work with the whole list. Similarly (even more so) for dictionary comprehensions

Re: [Python-3000] Set literal

2008-02-01 Thread Guido van Rossum
On Feb 1, 2008 4:07 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Not necessarily. We don't have dict comprehensions, and We don't? bash-3.2$ ./python.exe Python 3.0a2+ (py3k:60207, Jan 22 2008, 16:58:59) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license"

Re: [Python-3000] Set literal

2008-02-01 Thread Greg Ewing
Nicko van Someren wrote: > Do we really want set literals at all, given that set(...) exists? > > If we are going to have one then, it seems to make sense to have both. Not necessarily. We don't have dict comprehensions, and I don't remember there being many complaints about that. Also, if gen

Re: [Python-3000] Set literal

2008-02-01 Thread Nicko van Someren
On 30 Jan 2008, at 23:17, Greg Ewing wrote: > Nicko van Someren wrote: >> Personally I'd like set comprehensions to give me mutable sets, >> and so I feel set literals should do the same. > > Do you really want set comprehensions at all, given that > set(genexp) exists? Do we really want set l

Re: [Python-3000] Set literal

2008-01-30 Thread Terry Reedy
"Christian Heimes" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Greg Ewing wrote: | | Personally I'm more than happy to trade set comprehensions for optimized | frozen set literals. My code has more 'item in fixed_set' than sets. I | can't remember a project where I've used froz

Re: [Python-3000] Set literal

2008-01-30 Thread Guido van Rossum
On Jan 30, 2008 4:01 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Thomas Wouters wrote: > > > > On Jan 30, 2008 3:17 PM, Greg Ewing <[EMAIL PROTECTED] > > > wrote: > > > > Do you really want set comprehensions at all, given that > > set(genexp) exists? > > > > Too l

Re: [Python-3000] Set literal

2008-01-30 Thread Greg Ewing
Thomas Wouters wrote: > > On Jan 30, 2008 3:17 PM, Greg Ewing <[EMAIL PROTECTED] > > wrote: > > Do you really want set comprehensions at all, given that > set(genexp) exists? > > Too late. I thought Guido said it wasn't too late to change this? -- Greg _

Re: [Python-3000] Set literal

2008-01-30 Thread Christian Heimes
Greg Ewing wrote: > Do you really want set comprehensions at all, given that > set(genexp) exists? For me comprehension are a means to optimize common patterns in the sense of faster to execute, faster to read and faster to write. Do set comprehensions occur so often that {item for item in sequenc

Re: [Python-3000] Set literal

2008-01-30 Thread Thomas Wouters
On Jan 30, 2008 3:17 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Nicko van Someren wrote: > > Personally I'd like set comprehensions to give me mutable > > sets, and so I feel set literals should do the same. > > Do you really want set comprehensions at all, given that > set(genexp) exists? > Too

Re: [Python-3000] Set literal

2008-01-30 Thread Greg Ewing
Nicko van Someren wrote: > Personally I'd like set comprehensions to give me mutable > sets, and so I feel set literals should do the same. Do you really want set comprehensions at all, given that set(genexp) exists? -- Greg ___ Python-3000 mailing li

Re: [Python-3000] Set literal

2008-01-30 Thread Greg Ewing
Mike Klaas wrote: > over 120k loc: > > All uses of set(): > > $ pygrep '[^.a-z]set[(]' | grep -v unittest | wc > 3201583 24774 > > Empty set(): > > $ pygrep '[^.a-z]set[(][)]' | grep -v unittest | wc > 114 4787406 But that doesn't count uses of tuples that could be tur

Re: [Python-3000] Set literal

2008-01-29 Thread Nicko van Someren
On 28 Jan 2008, at 23:45, Greg Ewing wrote: > Guido van Rossum wrote: >> ... >> Have a look at PEP 218. > > That PEP proposes that there be no set literal or comprehension > syntax, and doesn't contain any discussion on whether such > syntax should produce sets or frozensets if it were to exist. I

Re: [Python-3000] Set literal

2008-01-29 Thread Jim Jewett
On 1/29/08, Mike Klaas <[EMAIL PROTECTED]> wrote: > On 29-Jan-08, at 2:29 PM, Greg Ewing wrote: > > Jim Jewett wrote: > >> The majority of uses need a mutable set that starts empty. > > Does anyone have evidence to support that assertion? > $ pygrep '[^.a-z]set[(]' | grep -v unittest | wc >

Re: [Python-3000] Set literal

2008-01-29 Thread Mike Klaas
On 29-Jan-08, at 2:29 PM, Greg Ewing wrote: > Jim Jewett wrote: > >> The majority of uses need a mutable set that starts empty. > > Does anyone have evidence to support that assertion? > > Thinking about my own code, I probably do membership > tests on constant sets (represented as tuples) about

Re: [Python-3000] Set literal

2008-01-29 Thread Greg Ewing
Jim Jewett wrote: > The majority of uses need a mutable set that starts empty. Does anyone have evidence to support that assertion? Thinking about my own code, I probably do membership tests on constant sets (represented as tuples) about as often as I build up mutable sets (or some equivalent da

Re: [Python-3000] Set literal

2008-01-29 Thread Jim Jewett
On 1/28/08, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Please don't reopen this. There are good reasons for 'set' to be the > default set type and 'frozenset' to appear like a poor cousin. For > one, their naming. This was all reasoned out long, long ago, in Python > 2.3 with the sets module. I

Re: [Python-3000] Set literal

2008-01-28 Thread Greg Ewing
Guido van Rossum wrote: > No, but it *does* make 'set' the "default" type, making you work > harder to get a frozenset. From this it follows that frozenset was > considered the lesser-useful type at the time. That logic assumes that one of them necessarily has to be harder to get than the other,

Re: [Python-3000] Set literal

2008-01-28 Thread Guido van Rossum
On Jan 28, 2008 3:45 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > On Jan 28, 2008 2:46 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > > > >>Is there a PEP we can refer to for confirmation of > >>said non-craziness? > > > > Have a look at PEP 218. > > That PEP proposes that t

Re: [Python-3000] Set literal

2008-01-28 Thread Greg Ewing
Guido van Rossum wrote: > On Jan 28, 2008 2:46 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > >>Is there a PEP we can refer to for confirmation of >>said non-craziness? > > Have a look at PEP 218. That PEP proposes that there be no set literal or comprehension syntax, and doesn't contain any discus

Re: [Python-3000] Set literal

2008-01-28 Thread Guido van Rossum
On Jan 28, 2008 2:46 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > This was all reasoned out long, long ago, in Python > > 2.3 with the sets module. If you insist I will try to write it up all > > again, but I'd rather you believe that we weren't crazy back then. > > Is th

Re: [Python-3000] Set literal

2008-01-28 Thread Greg Ewing
Guido van Rossum wrote: > This was all reasoned out long, long ago, in Python > 2.3 with the sets module. If you insist I will try to write it up all > again, but I'd rather you believe that we weren't crazy back then. Is there a PEP we can refer to for confirmation of said non-craziness? -- Greg

Re: [Python-3000] Set literal

2008-01-28 Thread Guido van Rossum
Please don't reopen this. There are good reasons for 'set' to be the default set type and 'frozenset' to appear like a poor cousin. For one, their naming. This was all reasoned out long, long ago, in Python 2.3 with the sets module. If you insist I will try to write it up all again, but I'd rather

Re: [Python-3000] Set literal

2008-01-28 Thread Jim Jewett
On 1/28/08, Greg Ewing <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > On Jan 26, 2008 8:39 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > >>However, my support for it has waned anyway. The > >> notation is also used for set comprehension > >> and those should be mutable. Set compre

Re: [Python-3000] Set literal

2008-01-28 Thread Greg Ewing
Guido van Rossum wrote: > On Jan 26, 2008 8:39 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > >>However, my support for it has waned anyway. The notation is also >>used for set comprehension and those should be mutable. > > Cool. That saves us a PEP. Vive le status quo. You're changing your

Re: [Python-3000] Set literal

2008-01-26 Thread Raymond Hettinger
>> However, my support for it has waned anyway. The notation is also >> used for set comprehension and those should be mutable. > > Cool. That saves us a PEP. Vive le status quo. It just wasn't me to be. Raymond ___ Python-3000 mailing list Python-30

Re: [Python-3000] Set literal

2008-01-26 Thread Guido van Rossum
On Jan 26, 2008 8:39 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > [Adam] > > Given that "x in {1,2,3}" can be optimized just as well with mutable > > sets (can somebody think of an example that can't?), do you still > > support immutable using the literal notation? > > From an optimization po

Re: [Python-3000] Set literal

2008-01-26 Thread Raymond Hettinger
[Adam] > Given that "x in {1,2,3}" can be optimized just as well with mutable > sets (can somebody think of an example that can't?), do you still > support immutable using the literal notation? >From an optimization point of view, it is still best to have {...} as a >frozenset. However, my suppo

Re: [Python-3000] Set literal

2008-01-26 Thread Adam Olsen
On Jan 24, 2008 9:12 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > For the record, I'm thinking Raymond has won this argument fair and > square, and I'm withdrawing my opposition. > > I hope it isn't too confusing that {1: 1} creates a *mutable* dict > while {1} creates an *immutable* frozenset

Re: [Python-3000] Set literal

2008-01-26 Thread Leif Walsh
On Jan 26, 2008 5:11 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > But didn't we start by establishing that users are rarely going to > create non-empty non-frozen sets anyway, because most algorithms > involving mutable sets start with an empty one? Even if users > occasionally write initializ

Re: [Python-3000] Set literal

2008-01-26 Thread Guido van Rossum
On Jan 26, 2008 2:02 PM, Georg Brandl <[EMAIL PROTECTED]> wrote: > Guido van Rossum schrieb: > > On Jan 26, 2008 1:45 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > >> Am strongly -1 on changing the repr for set to set({a, b, c}) . Creating > >> an innermost frozenset doubles the memory cons

Re: [Python-3000] Set literal

2008-01-26 Thread Georg Brandl
Guido van Rossum schrieb: > On Jan 26, 2008 1:45 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: >> Am strongly -1 on changing the repr for set to set({a, b, c}) . Creating >> an innermost frozenset doubles the memory consumption. > > Raymond, I think you're overestimating how often the repr()

Re: [Python-3000] Set literal

2008-01-26 Thread Raymond Hettinger
[GvR] > Raymond, I think you're overestimating how often the repr() of a set > actually gets eval()'ed. The repr is the model for how we enter things by hand. If the repr is set([1,2,3]), the that's how we will learn to type them into our programs. It's not the eval(repr(s)) round trip that's at

Re: [Python-3000] Set literal

2008-01-26 Thread Guido van Rossum
On Jan 26, 2008 1:45 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > Am strongly -1 on changing the repr for set to set({a, b, c}) . Creating an > innermost frozenset doubles the memory consumption. Raymond, I think you're overestimating how often the repr() of a set actually gets eval()'ed.

Re: [Python-3000] Set literal

2008-01-26 Thread Christian Heimes
Ron Adam wrote: > It's all very close. I think the frozenset({1,2,3}) example will get > faster if {..} notation becomes a frozen set, and set({...}) example will > slow down a bit. frozenset({1,2,3}) can be optimized and reduced to a simple return in frozenset_new() just like str("abc") return

Re: [Python-3000] Set literal

2008-01-26 Thread Raymond Hettinger
>>> should the repr for a set be set({a, b, c}) instead of set([a, b, c])? [Raymond] >> FWIW, running eval() on the repr is slower and less memory efficient with >> curly braces than with the square brackets. [Ron] > It's all very close. I think the frozenset({1,2,3}) example will get faster >

Re: [Python-3000] Set literal

2008-01-26 Thread Ron Adam
Raymond Hettinger wrote: >> should the repr for a set be set({a, b, c}) >> instead of set([a, b, c])? > > FWIW, running eval() on the repr is slower and less memory efficient with > curly braces than with the square brackets. This is what I get. >>> timeit.timeit("eval('frozenset({1,2,3})

Re: [Python-3000] Set literal

2008-01-26 Thread Nick Coghlan
Terry Reedy wrote: > "Nick Coghlan" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | More completely: > | > | () # empty tuple > | (1,)# 1 item tuple > | (1,2) # 2 item tuple > > 1,# 1 item tuple, no parens needed, trailing comma mandator

Re: [Python-3000] Set literal

2008-01-26 Thread Terry Reedy
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | More completely: | | () # empty tuple | (1,)# 1 item tuple | (1,2) # 2 item tuple 1,# 1 item tuple, no parens needed, trailing comma mandatory 1,2 # 2 item tuple, no parens nee

Re: [Python-3000] Set literal

2008-01-25 Thread Nick Coghlan
Guido van Rossum wrote: > On Jan 25, 2008 10:01 AM, Leif Walsh <[EMAIL PROTECTED]> wrote: >> On Jan 25, 2008 12:37 PM, Christian Heimes <[EMAIL PROTECTED]> wrote: >>> The pipe char is ambiguous because is no direction. It was suggested and >>> rejected last year. >> Out of almost-pure devil's advoc

Re: [Python-3000] Set literal

2008-01-25 Thread Raymond Hettinger
> should the repr for a set be set({a, b, c}) > instead of set([a, b, c])? FWIW, running eval() on the repr is slower and less memory efficient with curly braces than with the square brackets. Also, it may be easily misread as meaning: set([frozenset([a, b, c])]). If the latter is intended, t

Re: [Python-3000] Set literal

2008-01-25 Thread Guido van Rossum
On Jan 25, 2008 4:58 PM, Ron Adam <[EMAIL PROTECTED]> wrote: > How about also removing the {} as an empty dictionary? Then both > dictionary and set literals will require at least one item to be valid.No > confusion, and {} is not allowed because it's ambiguous (to users) as to > weather it's a

Re: [Python-3000] Set literal

2008-01-25 Thread Ron Adam
Raymond Hettinger wrote: > P.S. A small side-benefit is it may put an end for interminable requests for > a {:} or {/} notation for empty sets. There's not much need for a literal > for a empty frozenset (use "not s" instead). How about also removing the {} as an empty dictionary? Then bo

Re: [Python-3000] Set literal

2008-01-25 Thread Adam Olsen
On Jan 25, 2008 12:52 PM, Collin Winter <[EMAIL PROTECTED]> wrote: > > On Jan 24, 2008 10:40 PM, Adam Olsen <[EMAIL PROTECTED]> wrote: > > On Jan 24, 2008 5:12 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > > > Looking over the code base, frozensets are used rarely. > > > > So I don't think t

Re: [Python-3000] Set literal

2008-01-25 Thread Steven Bethard
On Jan 25, 2008 1:31 PM, J. Cliff Dyer <[EMAIL PROTECTED]> wrote: > > I'm a -0.9 on this one. I really like that Python is powerful, but also a > great pedagogical language. > > I don't like that whereas before you could teach someone {} creates a dict, > but now you have to say {} creates a dic

Re: [Python-3000] Set literal

2008-01-25 Thread J. Cliff Dyer
I'm a -0.9 on this one. I really like that Python is powerful, but also a great pedagogical language. I don't like that whereas before you could teach someone {} creates a dict, but now you have to say {} creates a dict, if there are colons inside, or it's empty, but otherwise creates a frozenset.

Re: [Python-3000] Set literal

2008-01-25 Thread Collin Winter
On Jan 24, 2008 10:40 PM, Adam Olsen <[EMAIL PROTECTED]> wrote: > On Jan 24, 2008 5:12 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > > Looking over the code base, frozensets are used rarely. > > > So I don't think this is warranted. > > > > There is no shortage for perfect use cases in the f

Re: [Python-3000] Set literal

2008-01-25 Thread Charles Merriam
> There are also « and », << and >> for those w/o UTF-8 support in their > mail client. On my keyboard the characters are available under [alt gr] > + y and x. Not elegant. It should look pretty. Code should look the same in all character encodings unless alternate codings for used for identifie

Re: [Python-3000] Set literal

2008-01-25 Thread Thomas Wouters
On Jan 25, 2008 10:01 AM, Leif Walsh <[EMAIL PROTECTED]> wrote: > On Jan 25, 2008 12:37 PM, Christian Heimes <[EMAIL PROTECTED]> wrote: > > The pipe char is ambiguous because is no direction. It was suggested and > > rejected last year. > > Out of almost-pure devil's advocacy, has <> been consider

Re: [Python-3000] Set literal

2008-01-25 Thread Thomas Wouters
On Jan 25, 2008 10:32 AM, Christian Heimes <[EMAIL PROTECTED]> wrote: > Leif Walsh wrote: > > Out of almost-pure devil's advocacy, has <> been considered? My first > > instinct is that it would be ambiguous with less-than/greater-than, > > but if someone can convince me otherwise, might it work?

Re: [Python-3000] Set literal

2008-01-25 Thread Christian Heimes
Leif Walsh wrote: > Out of almost-pure devil's advocacy, has <> been considered? My first > instinct is that it would be ambiguous with less-than/greater-than, > but if someone can convince me otherwise, might it work? After all, > it's the only other balanced pair of punctuation I see on my keyb

Re: [Python-3000] Set literal

2008-01-25 Thread Guido van Rossum
On Jan 25, 2008 10:15 AM, nathan binkert <[EMAIL PROTECTED]> wrote: > > No, there are too many syntactic situations where this would make the > > grammar ambiguous or tortuous. We don't want to move beyond LL(1). > > (Apart from parsing indentation and nested parentheses, of course -- > > which act

Re: [Python-3000] Set literal

2008-01-25 Thread Guido van Rossum
On Jan 25, 2008 10:01 AM, Leif Walsh <[EMAIL PROTECTED]> wrote: > On Jan 25, 2008 12:37 PM, Christian Heimes <[EMAIL PROTECTED]> wrote: > > The pipe char is ambiguous because is no direction. It was suggested and > > rejected last year. > > Out of almost-pure devil's advocacy, has <> been considere

Re: [Python-3000] Set literal

2008-01-25 Thread Leif Walsh
On Jan 25, 2008 12:37 PM, Christian Heimes <[EMAIL PROTECTED]> wrote: > The pipe char is ambiguous because is no direction. It was suggested and > rejected last year. Out of almost-pure devil's advocacy, has <> been considered? My first instinct is that it would be ambiguous with less-than/greate

Re: [Python-3000] Set literal

2008-01-25 Thread Christian Heimes
Dj Gilcrease wrote: > This probably will not go over well, but why not use the pipe > character to define a frozenset? > > if urltxt in |'html', 'xml', 'php'|: The pipe char is ambiguous because is no direction. It was suggested and rejected last year. Christian

Re: [Python-3000] Set literal

2008-01-25 Thread Dj Gilcrease
On Jan 24, 2008 8:12 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > I hope it isn't too confusing that {1: 1} creates a *mutable* dict > while {1} creates an *immutable* frozenset. I still find this slightly > inelegant. But the practicality of being able to treat set literals as > compile-time

Re: [Python-3000] Set literal

2008-01-25 Thread Christian Heimes
Raymond Hettinger wrote: > I think it would be more useful for the {e1, e2, e3} literal to be a > frozenset instead of a set. +1 from me Christian ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000

Re: [Python-3000] Set literal

2008-01-25 Thread Nick Coghlan
Mark Summerfield wrote: > On 2008-01-25, Guido van Rossum wrote: >> For the record, I'm thinking Raymond has won this argument fair and >> square, and I'm withdrawing my opposition. >> >> I hope it isn't too confusing that {1: 1} creates a *mutable* dict >> while {1} creates an *immutable* frozense

Re: [Python-3000] Set literal

2008-01-25 Thread Aahz
On Fri, Jan 25, 2008, Mark Summerfield wrote: > > Python 3 is going to break compatibility anyway. I thought one of the > purposes of having a new major release was to allow for such changes. > > In 2 or 3 years from now Python 3 will be "Python" for most people, and > confusing inconsistencies wo

Re: [Python-3000] Set literal

2008-01-25 Thread Gustavo Niemeyer
> I hope it isn't too confusing that {1: 1} creates a *mutable* dict > while {1} creates an *immutable* frozenset. I still find this slightly > inelegant. But the practicality of being able to treat set literals as > compile-time constants wins me over. Another point in favor of Raymond's suggest

Re: [Python-3000] Set literal

2008-01-25 Thread Christian Heimes
Mark Summerfield wrote: > Python 3 is going to break compatibility anyway. I thought one of the > purposes of having a new major release was to allow for such changes. Please stop the discussion! Guido already voted against it. I assume most of the remaining core developers agree with me that thre

Re: [Python-3000] Set literal

2008-01-25 Thread Marcin ‘Qrczak’ Kowalczyk
Dnia 25-01-2008, Pt o godzinie 07:18 +, Mark Summerfield pisze: > If you're going to make the change, why not make things consistent: How often do you need the empty frozenset (which will stay as such), compared to an empty dict (which will probably get filled later)? The real inconsistency

Re: [Python-3000] Set literal

2008-01-25 Thread Oleg Broytmann
On Fri, Jan 25, 2008 at 09:29:49AM +, Mark Summerfield wrote: > In 2 or 3 years from now Python 3 will be "Python" for most people It depends on how much it breaks. If Python 3 breaks too much people may find it is a completely new language and decide to switch to another language instead o

Re: [Python-3000] Set literal

2008-01-25 Thread Mark Summerfield
On 2008-01-25, Steven Bethard wrote: > On Jan 25, 2008 12:18 AM, Mark Summerfield <[EMAIL PROTECTED]> wrote: > > On 2008-01-25, Guido van Rossum wrote: > > > For the record, I'm thinking Raymond has won this argument fair and > > > square, and I'm withdrawing my opposition. > > > > > > I hope it is

Re: [Python-3000] Set literal

2008-01-24 Thread Steven Bethard
On Jan 25, 2008 12:18 AM, Mark Summerfield <[EMAIL PROTECTED]> wrote: > On 2008-01-25, Guido van Rossum wrote: > > For the record, I'm thinking Raymond has won this argument fair and > > square, and I'm withdrawing my opposition. > > > > I hope it isn't too confusing that {1: 1} creates a *mutable*

Re: [Python-3000] Set literal

2008-01-24 Thread Mark Summerfield
On 2008-01-25, Guido van Rossum wrote: > For the record, I'm thinking Raymond has won this argument fair and > square, and I'm withdrawing my opposition. > > I hope it isn't too confusing that {1: 1} creates a *mutable* dict > while {1} creates an *immutable* frozenset. I still find this slightly >

Re: [Python-3000] Set literal

2008-01-24 Thread John Barham
Martin v. Löwis" wrote: > Are you implying that the search is faster for a tuple if the set is > small? That was my intuition but the measurements say otherwise. ;) Even for sets as small as two or three elements, searches in frozensets are faster than within tuples. See my tuple vs. frozenset

Re: [Python-3000] Set literal

2008-01-24 Thread Adam Olsen
On Jan 24, 2008 5:12 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > Looking over the code base, frozensets are used rarely. > > So I don't think this is warranted. > > There is no shortage for perfect use cases in the form: > >if urlext in {'html', 'xml', 'php'}: > . . . > > > If

Re: [Python-3000] Set literal

2008-01-24 Thread Martin v. Löwis
> But getting back to the original issue, what does using frozensets > gain you over using a tuple: > > if urlext in ('html', 'xml', 'php'): > > Given that tuples are also immutable, couldn't the peepholer also > optimize the tuple as a compile time constant? py> def f(): ... if urlext in ('ht

Re: [Python-3000] Set literal

2008-01-24 Thread Guido van Rossum
Thanks! I tried it again with a 2-element tuple and frozenset, and with hits on the first and second item, and with a miss. I am convinced. Even for a 2-element set, the frozenset comes out ahead except compared to a hit on the first tuple item. So let's leave this alone -- if the user writes a tup

Re: [Python-3000] Set literal

2008-01-24 Thread John Barham
Guido wrote: > (I suspect for a 2-element set of ints or strings, translating "x in > {C1, C2}" into "x in (C1, C2)" might actually be a slight win since > probing a tuple must be much faster than probing a set; but that's a > detail.) A trivial but hopefully fairly representative benchmark: Act

Re: [Python-3000] Set literal

2008-01-24 Thread Guido van Rossum
For the record, I'm thinking Raymond has won this argument fair and square, and I'm withdrawing my opposition. I hope it isn't too confusing that {1: 1} creates a *mutable* dict while {1} creates an *immutable* frozenset. I still find this slightly inelegant. But the practicality of being able to

[Python-3000] Set literal

2008-01-24 Thread Raymond Hettinger
[Jim Jewett] > I thought you tried changing those tuples to frozensets >(because it was semantically better), and found that it > didn't actually win for tuples of length 2 or 3. The sets were faster. The automatic transformation didn't go in because it changed semantics -- the searched for item

Re: [Python-3000] Set literal

2008-01-24 Thread Jim Jewett
On 1/24/08, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > [John Barham] > > But getting back to the original issue, what does using > > frozensets gain you over using a tuple: > > > > if urlext in ('html', 'xml', 'php'): > > With sets, the search is O(1). > With tuples, it is O(n). > Sets win on i

Re: [Python-3000] Set literal

2008-01-24 Thread Brett Cannon
On Jan 24, 2008 5:38 PM, Jeffrey Yasskin <[EMAIL PROTECTED]> wrote: > On Jan 24, 2008 4:13 PM, <[EMAIL PROTECTED]> wrote: > > > > Guido> Looking over the code base, frozensets are used rarely. So I > > Guido> don't think this is warranted. > > > > I kind of like the idea. Raymond's argume

Re: [Python-3000] Set literal

2008-01-24 Thread Jeffrey Yasskin
On Jan 24, 2008 4:13 PM, <[EMAIL PROTECTED]> wrote: > > Guido> Looking over the code base, frozensets are used rarely. So I > Guido> don't think this is warranted. > > I kind of like the idea. Raymond's arguments make sense to me. Most of the > time if I bother to create a set literal it

Re: [Python-3000] Set literal

2008-01-24 Thread Steven Bethard
On Jan 24, 2008 5:13 PM, <[EMAIL PROTECTED]> wrote: > > Guido> Looking over the code base, frozensets are used rarely. So I > Guido> don't think this is warranted. > > I kind of like the idea. Raymond's arguments make sense to me. Most of the > time if I bother to create a set literal it

[Python-3000] Set literal

2008-01-24 Thread Raymond Hettinger
[John Barham] > But getting back to the original issue, what does using > frozensets gain you over using a tuple: > > if urlext in ('html', 'xml', 'php'): With sets, the search is O(1). With tuples, it is O(n). Sets win on inputs longer than 1. Raymond ___

Re: [Python-3000] Set literal

2008-01-24 Thread John Barham
On Jan 24, 2008 4:23 PM, Barry Warsaw wrote: > On Jan 24, 2008, at 7:12 PM, Raymond Hettinger wrote: > > >> Looking over the code base, frozensets are used rarely. > >> So I don't think this is warranted. > > > > There is no shortage for perfect use cases in the form: > > > > if urlext in {'html

Re: [Python-3000] Set literal

2008-01-24 Thread Barry Warsaw
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Jan 24, 2008, at 7:12 PM, Raymond Hettinger wrote: >> Looking over the code base, frozensets are used rarely. >> So I don't think this is warranted. > > There is no shortage for perfect use cases in the form: > > if urlext in {'html', 'xml', 'php

Re: [Python-3000] Set literal

2008-01-24 Thread skip
Guido> Looking over the code base, frozensets are used rarely. So I Guido> don't think this is warranted. I kind of like the idea. Raymond's arguments make sense to me. Most of the time if I bother to create a set literal it would be to use it as a constant. Skip __

[Python-3000] Set literal

2008-01-24 Thread Raymond Hettinger
> Looking over the code base, frozensets are used rarely. > So I don't think this is warranted. There is no shortage for perfect use cases in the form: if urlext in {'html', 'xml', 'php'}: . . . If the curly braces are taken to mean a frozenset, then the peepholer can code the whol

Re: [Python-3000] Set literal

2008-01-24 Thread Guido van Rossum
Looking over the code base, frozensets are used rarely. So I don't think this is warranted. On Jan 24, 2008 2:32 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > I think it would be more useful for the {e1, e2, e3} literal to be a > frozenset instead of a set. > > In expressions like "x in {'ht

[Python-3000] Set literal

2008-01-24 Thread Raymond Hettinger
I think it would be more useful for the {e1, e2, e3} literal to be a frozenset instead of a set. In expressions like "x in {'html', 'xml', 'php'}" the compiler could optimize away the set construction and treat it as a constant. In cases where we want to build-up mutable sets, we need to start