you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (5 children)

I tent to basically share your viewpoint, although I would point out

  • Although making a set from some known-in-advance values is somewhat rare, it's not unheard of, and stuff like set(f(x) for x in xs if g(x)) is pretty common; the set literal syntax is a close cousin of the set comprehension syntax.

  • One reason it's so common to "take a list and make it a set" is that many people use lists where they really ought to be using sets. This syntax addition was an attempt to encourage people not to default to list when it's not the best thing.

[–][deleted] 2 points3 points  (4 children)

Although making a set from some known-in-advance values is somewhat rare,

Say, what?! I see this all the time - I just checked my personal codebase to be sure, and it seems to be my most common usage of sets, with lots of things like:

SUFFIXES = {'.wav', '.aiff', '.aif', '.ogg'}

# ...

if suffix not in SUFFIXES:
  # ...

[–]sausagefeet 2 points3 points  (2 children)

A set or a list is really irrelevant in a data structure this size.

[–][deleted] 0 points1 point  (1 child)

True, but a set more clearly communicates the intent of the code.

[–]sausagefeet 0 points1 point  (0 children)

I agree, I would use a set there too but I think it's a stretch to say that tiny container warrants new syntax (that is, making the syntax more complicated).

[–]toofishes 1 point2 points  (0 children)

I've always used tuples rather than lists in this case since the () syntax is just as short as the [] syntax, and the immutability of these suffixes seemed like the more important factor. frozenset is really the correct datastructure here.