On 4/27/06, Gareth McCaughan <[EMAIL PROTECTED]> wrote: > On Thursday 2006-04-27 11:42, Georg Brandl wrote: > > Kay Schluehr wrote: > ... > > > Furthermore: what about notions of infinite sets? > > > > Can you elaborate on that? > > Seems to me that if you want infinite sets, you want some type > other than "set". Ah, the wonders of duck typing. (Just as if > you want mappings with infinite domain, you want a type other > than "dict".) <>
This discussion has concentrated too heavily on the correspondence with mathematical sets and has proved to be somewhat of a chimaera. Python sets are _data structures_, and while they share some aesthetic similarities with the mathematical homonym, drawing on the latter for more than initial inspiration is flawed. It is easy to illustrate why: Assume someone wanted to work with math sets in python. Would set() cover any, let alone most use cases? Of interest is reasoning about their existence, emptiness, finitude, etc. How often do you want to iterate over a mathematical set? I've used set()s extensively since they were introduced. Many of my uses ignore the non-duplicative aspects of sets entirely, and use them for their algorithmic properties (O(1) insertion/containment tests). I particularly dislike any notion of using a phi or phi-like symbol to represent python set construction. The mathematical empty set is a totally different beast. True: ø is ø. False: set() is set(). Grepping through my source code. I find many uses of literal set construction. About half are frozenset([...]), half set([...]), but almost all the set([...]) construction calls should have been frozensets (but weren't due to laziness in unittest, etc.). there are also several instances where I would have used (frozen) sets over lists/tuples had a syntactic shortcut existed. I'm ambivalent on the need for an empty set literal. 'set()' is fine to type. Nor do I think {<gen expr>} has any advantage over set(<genexp>). But {} notation for frozensets would be a boon. Interestingly, I noticed that most of my used of { <key>:<value>, ... } dict construction expressions are used as "frozen" dicts. Despite that, I'm not bothered by these dicts being mutable. As so, were a {} set construction syntax to create sets rather than frozensets, I would likely still use it in place of frozenset. -Mike _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com