News for hackers. Stuff that matters.
Re:Performance Analysis of Python's Dict() and {} by colpabar on Monday January 22, 2024 @03:31PM (#39095008)
You could argue that since `{}` is also technically an empty set, `dict()` is more explicit.
Re:Performance Analysis of Python's Dict() and {} by masklinn on Monday January 22, 2024 @03:47PM (#39095215)
Except `{}` is never an empty set.
Re:Performance Analysis of Python's Dict() and {} by colpabar on Monday January 22, 2024 @03:58PM (#39095346)
> x = set()

> x

set()

Well now I know! However I still think the shared usage of curly braces for dicts and sets could be somewhat confusing.

> x = {1, 2, 3}

> x

{1, 2, 3}

(But maybe no one should listen to me because I don't know how to do code blocks on HN.)

Re:Performance Analysis of Python's Dict() and {} by tczMUFlmoNk on Monday January 22, 2024 @04:56PM (#39096051)
Indent by four spaces. :-)
Re:Performance Analysis of Python's Dict() and {} by pwdisswordfishc on Tuesday January 23, 2024 @03:10AM (#39100729)
The empty set is `{*()}`.
Re:Performance Analysis of Python's Dict() and {} by empiko on Tuesday January 23, 2024 @03:55AM (#39101043)
this is beautiful
Re:Performance Analysis of Python's Dict() and {} by alanwreath on Tuesday January 23, 2024 @01:22PM (#39107362)
never seen

    {*()}
    
but I guess it is equivalent to

    set()
    
I've noticed this in python in another place

    f"{var}"
    
is the same as

    str(var)
    
there was some other place I can't recall also noticing that (at least my perception understands that) Python is trying to kill my code golf tendencies.

That said, it's probably just my own superstition and of course it doesn't remove my premature optimization tendencies...