HN2new | past | comments | ask | show | jobs | submitlogin

But there is some weird stuff in Python syntax. Like, why do you create a dict with {} but access it with []? It always felt to me like an organic language, not one that was planned with consistency in mind (which is fine, of course).


It's also used for creating lists, but [] is syntax for retrieving a value from a container:

https://docs.python.org/2/reference/datamodel.html#emulating...

Or, the earliest I could quickly find:

https://docs.python.org/release/1.5/ref/ref-5.html#HEADING5-...

The access pattern is probably the right aspect to make consistent (at least in the context of duck typing). If the access isn't generalized across various types they might as well use named methods.

edit: I corrected the anchor in the second link.


Declaration doesn't reflect usage, it's not a helpful principle in general. You create tuples with () but access them with [], and the fact that [a, b, c] is a list has very little to do with the fact that you use [] to index into it. The {} syntax for dictionary literals is reasonably common; Ruby's looks fairly similar, and Javascript uses almost exactly the same syntax, which many people will be familiar with thanks to JSON. Are there any other popular syntices for dict literals?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: