[Python-3000] sets in P3K?

Michael Chermside mcherm at mcherm.com
Fri Apr 28 18:15:20 CEST 2006


Barry writes:
> Well here's another nutty idea.  We actually have two ways to create
> literal tuples, right?
>
> x = 1, 2, 3
> x = (1, 2, 3)
>
> So let's keep the first and hijack the second to be set constructor
> notation.

Nutty and wrong (but don't let that stop you from continuing to
think up interesting alternative approaches in the future!). Those
are not two different literals... both use the comma literal to
create a tuple, and the second has parentheses (used for grouping)
around it.

For instance, this is all legal Python:

    # warning: untested code
    x = "123"
    y = ("123")

    x = {1:2, 3:4}
    y = ({1:2, 3:4})

    x = [1, 2, 3]
    y = ([1, 2, 3])

In each case, x and y are set to the same value.

The fact that '()' is special notation for the empty tuple is
just misleading -- parentheses have nothing to do with tuple
notation for non-empty tuples.

-- Michael Chermside


More information about the Python-3000 mailing list