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

The inclusion of that made me question the entire thing. It's just so...wrong.

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

    a = 123
    b = 'foo'
    d = {a:456, b:123, 2.3:'2.3'}
    print(d)

    >>> {123: 456, 'foo': 123, 2.3: '2.3'}



>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.


It seems he just doesn't want to type quotes and is OK with breaking everything else to get that. Which is fine, but no one else supports that change request.




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

Search: