Bitten by my C/Java experience
random832 at fastmail.us
random832 at fastmail.us
Mon May 4 17:16:03 EDT 2015
On Mon, May 4, 2015, at 16:57, Andrew Cooper wrote:
> * {} is an empty set(), not dict().
You've got it backwards.
> Particularly subtle when combined with **kwargs
The function in your example below _always_ returns a set, and kwargs is
always a dict. There's no subtlety outside of the repr output. The fact
that the empty set (as a result of empty kwargs) repr's as set() is a
consequence of the fact that {} is a dict.
>
> $ python3
> Python 3.4.0 (default, Apr 11 2014, 13:05:11)
> [GCC 4.8.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def foo(**kwargs):
> ... return { (k, kwargs[k]) for k in kwargs }
> ...
> >>> foo()
> set()
> >>> foo(a=1)
> {('a', 1)}
> >>>
>
> ~Andrew
> --
> https://mail.python.org/mailman/listinfo/python-list
--
Random832
More information about the Python-list
mailing list