Re: Revisiting a frozenset display literal
On 16/01/2022 14:23, Marco Sulla wrote:
I think it could also be cool to create a literal frozenset this way:
a = fs{1, 2, 3}
or, why not, a frozenset comprehension:
a = fs{i+1 for i in range(3)}
Maybe too much? +0.5 It would be nice for consistency (and perhaps performance). But you can already say a = frozenset({i+1 for i in range(3)}) which is not too bad.
On Sun, 16 Jan 2022 at 14:14, Rob Cliffe via Python-ideas <python-ideas@python.org> wrote:
How about fs{1, 2, 3} ? Best wishes Rob Cliffe
On 16/01/2022 12:41, Chris Angelico wrote: > On Sun, Jan 16, 2022 at 11:18 PM Steven D'Aprano <steve@pearwood.info> wrote: >> On Sun, Jan 16, 2022 at 09:18:40PM +1100, Chris Angelico wrote: >> >>> While it's tempting, it does create an awkward distinction. >>> >>> f(1, 2, 3) # look up f, call it with parameters >>> f[1, 2, 3] # look up f, subscript it with paramters >>> f{1, 2, 3} # construct a frozenset >> You forgot >> >> f"1, 2, {x+1}" # eval some code and construct a string >> >> Not to mention: >> >> r(1, 2, 3) # look up r, call it with parameters >> r[1, 2, 3] # look up r, subscript it >> r"1, 2, 3" # a string literal > Strings behave differently in many many ways. Are there any non-string > types that differ? > >> Reading this makes my eyes bleed: >> >> >>> <1, 2, 3> < <1, 2, 3, 4> >> True > Fair point, but I can't imagine people comparing two literals like > that. It's not quite as bad if you replace the left side with a > variable or calculation, though it's still kinda weird. > >>> Unfortunately there aren't many symbols available, and Python's kinda >>> locked into a habit of using just one at each end (rather than, say, >>> (<1, 2, 3>) or something), so choices are quite limited. >> Triple quoted strings say hello :-) > See above, strings are different, and people treat them differently. > >> {{1, 2, 3}} would work, since that's currently a runtime error. But I >> prefer the f{} syntax. >> > Yeah, I think that ship has sailed. Double punctuation just isn't > Python's thing, so there aren't really any good ways to shoehorn more > data types into fewer symbols. > > ChrisA > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-leave@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/PMK36C... > Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SWDTEH... Code of Conduct: http://python.org/psf/codeofconduct/
participants (1)
-
Rob Cliffe