Hacker News new | past | comments | ask | show | jobs | submit login

>Does the author not realize that you can use (almost) anything as a dict key?

You can do that in JS too, it's just coerced to string, so you can do e.g.

  {foo: "bar"}
where foo is not a variable, but assumed to be the string foo. In Python you can't, because you couldn't tell if it's foo the string, or a reference to an existing (or non-existing) foo variable.

That said, in JS, not only you're limited to using (real or coerced) strings as keys to Objects, but you also need to use the square bracket:

  {[foo]: "bar"}
syntax, so it can tell that you need it to use the value of the variable foo as the key (else it will understand {"foo": "bar"}).



That's different though. In python there is no coercion going on with the keys.




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

Search: