builtin set literal

  • Thread starter =?ISO-8859-1?Q?Sch=FCle_Daniel?=
  • Start date
S

Steven Bethard

Steven Bethard:
> While Python 3.0 is not afraid to break backwards
> compatibility, it tries to do so only when there's a very substantial
> advantage.

I understand, but this means starting already to put (tiny)
inconsistencies into Python 3.0...

Well, there's going to be an inconsistency one way or another:

Lists:
[1, 2]
[1]
[]

Dicts:
{1:2, 2:1}
{1:2}
{}

Sets:
{1, 2}
{1}
set()

Note that if we used {} for the empty set and {:} for the empty dict,
then sets would be consistent, but dicts would be inconsistent. And if
you're really worried about consistencies, take a look at the current
state of tuples:

1, 2
1,
()

There's just not an obvious *right* answer here, so it's better to stick
with the backwards compatible version.

STeVe
 
D

Dave Opstad

Paul Rubin said:
[...] However, Python seems to use the -ed suffix for the
non-mutating versions of these functions, e.g. sorted(list) instead
of the mutating list.sort().

I've found this to be useful in my own Python libraries. For instance, a
graphic object has move(), scale() etc. methods which mutate, and
moved(), scaled() etc. methods which return new instances. It's
English-specific, but still mnemonically useful.
 
B

bearophileHUGS

Steven Bethard:
take a look at the current state of tuples:
1, 2
1,
()

That's not a good situation. I presume the situation/syntax of tuples
in Python 2.x can't be improved. But can it be improved for Py 3.0?
Notes:
- I think in Matlab a single element is seen as the same thing as an
array with len = 1.
- I think Ruby solves the problem of the list/tuple with a freezing
function/operator (like I suggested some time ago).

Bye,
bearophile
 
S

Steven Bethard

Steven Bethard:

That's not a good situation. I presume the situation/syntax of tuples
in Python 2.x can't be improved. But can it be improved for Py 3.0?

I'm not really losing any sleep over the current tuple syntax. ;-) The
empty tuple is so uncommon in my code that the fact that it's spelled
differently just doesn't bother me.

And anyway, if I've learned anything from the Python community over the
years, it's that syntax is best left to Guido. ;-)

STeVe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top