[Python-ideas] frozenset literals
Stefan Behnel
stefan_ml at behnel.de
Sat Feb 2 08:34:27 CET 2013
Hua Lu, 02.02.2013 07:24:
> This is similar to another proposal:
> http://mail.python.org/pipermail/python-3000/2008-January/011798.html
>
> Anyway, I was using ast.literal_eval and attempted to use frozenset({...})
> as a key in a dictionary, which failed, because frozenset isn't a literal
This has nothing to do with being a literal or not. The way you created
your frozenset doesn't impact its behaviour.
Could you give an example of what's not working for you? Frozensets as dict
keys work just fine for me:
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> frozenset({1,2,3})
frozenset({1, 2, 3})
>>> hash(frozenset({1,2,3}))
-7699079583225461316
>>> { frozenset({1,2,3}) : 1 }
{frozenset({1, 2, 3}): 1}
Stefan
More information about the Python-ideas
mailing list