[Python-3000] sets in P3K?

Jim Jewett jimjjewett at gmail.com
Wed Apr 26 18:07:59 CEST 2006


On 4/25/06, Edward Loper <edloper at gradient.cis.upenn.edu> wrote:
> I think that a significant motivation for people that propose set
> literals is that the following is just plain ugly:
>
>     s = set([1,2,3])
>
> It seems much more natural to write:
>
>     s = set(1, 2, 3)
>
>    s = set.from_iter(my_list)
>    s = set.from_iter(enumerate(my_list))
>    s = set.from_iter(x for x in collection if x>10)

Alternatively, define a classmethod for the literal form.  For me,
even the much longer

    s = set.literal(1, 2, 3)

would be much better than

    s = set([1,2,3])

Nick's NumPy-inspired suggestion of

    s = set[1, 2, 3]

is probably even better, though I'm not sure I would like what it does
to the rest of the language.  (The [] vs () would be arbitrary
(historical), and
    Class.__getitem__() would be almost unrelated to
    Class().__getitem__().  )

-jJ


More information about the Python-3000 mailing list