News for hackers. Stuff that matters.
Re:Performance Analysis of Python's Dict() and {} by kevincox on Monday January 22, 2024 @03:37PM (#39095083)
For string keys it can be as it is `dict(a=1, b=2, c=3)` vs `{"a": 1, "b": 2, "c": 3}`. There is a lot of `"` noise on the latter.
Re:Performance Analysis of Python's Dict() and {} by formerly_proven on Monday January 22, 2024 @03:51PM (#39095262)
50% less noise with ‘ though dict is still slightly easier to read; you can also convey that the keys are supposed to be valid identifiers.
Re:Performance Analysis of Python's Dict() and {} by tweakimp on Monday January 22, 2024 @04:15PM (#39095569)
I wish I could do {a=3, b=2}
Re:Performance Analysis of Python's Dict() and {} by coldtea on Monday January 22, 2024 @07:32PM (#39097664)
You can in Javascript - but with the caveat that the keys can only be strings.

Without that, if Python allowed it, would it do given:

  a = "xxx"
  test_dict = {a=3, b=2}
would it take test_dict to mean {"xxx":3, "b":2} or {"a":3, "b":2} ?

JS does the latter always, so the variable a is not related to the literal key a which is understood as an unquoted string "a":

  > a = "xxx"
  'xxx'
  > test_dict = {a:3, b:2}
  { a: 3, b: 2 }
  > test_dict["xxx"]
  undefined
  > test_dict["a"]
  3
Re:Performance Analysis of Python's Dict() and {} by lifthrasiir on Tuesday January 23, 2024 @11:07PM (#39113504)
The assignment operator `=` can never appear in a valid Python expression, so `{a=3, b=2}` should be distinguishable from `{a: 3, b: 2}`. (So does JS, where `{[a]: 3, [b]: 2}` would evaluate a and b.)
Re:Performance Analysis of Python's Dict() and {} by pwdisswordfishc on Tuesday January 23, 2024 @03:08AM (#39100722)
At this point, just use a dataclass.
Re:Performance Analysis of Python's Dict() and {} by paulddraper on Monday January 22, 2024 @06:31PM (#39097080)
Of course, for anything except string keys, that isn't even an option.
Re:Performance Analysis of Python's Dict() and {} by coldtea on Monday January 22, 2024 @07:27PM (#39097625)
No great reason it couldn't be though:

dict(1=5, 6=7, 7="aaa")

dict(hashableInstance="foo", anotherHashableInstance=23, (1,5)=8)

except Python syntax choices of course.

Re:Performance Analysis of Python's Dict() and {} by paulddraper on Monday January 22, 2024 @08:49PM (#39098466)
Is 1 a integer or a string?
Re:Performance Analysis of Python's Dict() and {} by coldtea on Monday January 22, 2024 @10:46PM (#39099388)
It's an integer (in the, not supported, format I show as something Python could have supported).

And if they wanted a string, they'd do it like:

dict("1"=5, 6=7, 7="aaa")