Irmen de Jong writes:
> I would use:
> test_dct.items() <= base_dct.items()
I think you need an explicit cast:
set(test_dct.items()) <= set(base_dct.items())
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 22, 8:18 am, MRAB wrote:
> On 22/04/2011 15:57, Irmen de Jong wrote:
>
>
>
>
>
>
>
> > On 22-4-2011 15:55, Vlastimil Brom wrote:
> >> Hi all,
> >> I'd like to ask for comments or advice on a simple code for testing a
> >> "subdict", i.e. check whether all items of a given dictionary are
> >
On Fri, 22 Apr 2011 07:38:38 -0700, Chris Rebert wrote:
> Also, the following occurs to me as another idiomatic, perhaps more
> /conceptually/ elegant possibility, but it's /practically/ speaking
> quite inefficient (unless perhaps some dict view tricks can be
> exploited):
>
> def is_subdict(sub
On 22/04/2011 21:31, Vlastimil Brom wrote:
Thanks everyone for your opinions and suggestions!
I especially like the all(...) approaches of MRAB and Peter Otten,
however, the set conversion like
set(test_dct.items())<= set(base_dct.items())
True
looks elegant too.
That works only if the values
Thanks everyone for your opinions and suggestions!
I especially like the all(...) approaches of MRAB and Peter Otten,
however, the set conversion like
>>> set(test_dct.items()) <= set(base_dct.items())
True
looks elegant too.
In both approaches I can get rid of the negated comparison and the
additi
Zero Piraeus wrote:
> :
>
> On 22 April 2011 13:30, Peter Otten <__pete...@web.de> wrote:
> def is_subdict(test_dct, base_dct):
>> ... return test_dct <= base_dct and all(test_dct[k] == base_dct[k]
>> for ... k in test_dct)
>> ...
> is_subdict({1:0}, {2:0})
>> Traceback (most recent c
:
On 22 April 2011 13:30, Peter Otten <__pete...@web.de> wrote:
def is_subdict(test_dct, base_dct):
> ... return test_dct <= base_dct and all(test_dct[k] == base_dct[k] for
> ... k in test_dct)
> ...
is_subdict({1:0}, {2:0})
> Traceback (most recent call last):
> File "", line 1, in
Zero Piraeus wrote:
>>> Anything wrong with this?
>>>
>>> def is_subdict(test_dct, base_dct):
>>> return test_dct <= base_dct and all(test_dct[k] == base_dct[k] for
>>> k in test_dct)
>>
>> It may raise a KeyError.
>
> Really? That was what ``test_dct <= base_dct and`` ... is supposed to
> preven
:
>> Anything wrong with this?
>>
>> def is_subdict(test_dct, base_dct):
>> return test_dct <= base_dct and all(test_dct[k] == base_dct[k] for
>> k in test_dct)
>
> It may raise a KeyError.
Really? That was what ``test_dct <= base_dct and`` ... is supposed to
prevent. Have I missed something?
On 22/04/2011 15:57, Irmen de Jong wrote:
On 22-4-2011 15:55, Vlastimil Brom wrote:
Hi all,
I'd like to ask for comments or advice on a simple code for testing a
"subdict", i.e. check whether all items of a given dictionary are
present in a reference dictionary.
Sofar I have:
def is_subdict(tes
Zero Piraeus wrote:
> :
>
>>> I'd like to ask for comments or advice on a simple code for testing a
>>> "subdict", i.e. check whether all items of a given dictionary are
>>> present in a reference dictionary.
>
> Anything wrong with this?
>
> def is_subdict(test_dct, base_dct):
> return tes
On 22-4-2011 15:55, Vlastimil Brom wrote:
> Hi all,
> I'd like to ask for comments or advice on a simple code for testing a
> "subdict", i.e. check whether all items of a given dictionary are
> present in a reference dictionary.
> Sofar I have:
>
> def is_subdict(test_dct, base_dct):
> """Test
On Freitag 22 April 2011, Vlastimil Brom wrote:
> check whether all items of a given dictionary are
> present in a reference dictionary
I would not call this is_subdict. That name does not
clearly express that all keys need to have the same
value.
set(subdict.items()) <= set(reference.items())
s
:
>> I'd like to ask for comments or advice on a simple code for testing a
>> "subdict", i.e. check whether all items of a given dictionary are
>> present in a reference dictionary.
Anything wrong with this?
def is_subdict(test_dct, base_dct):
return test_dct <= base_dct and all(test_dct[k]
On Fri, Apr 22, 2011 at 6:55 AM, Vlastimil Brom
wrote:
> Hi all,
> I'd like to ask for comments or advice on a simple code for testing a
> "subdict", i.e. check whether all items of a given dictionary are
> present in a reference dictionary.
> Sofar I have:
>
> def is_subdict(test_dct, base_dct):
Vlastimil Brom wrote:
> Hi all,
> I'd like to ask for comments or advice on a simple code for testing a
> "subdict", i.e. check whether all items of a given dictionary are
> present in a reference dictionary.
> Sofar I have:
>
> def is_subdict(test_dct, base_dct):
> """Test whether all the it
On 22/04/2011 14:55, Vlastimil Brom wrote:
Hi all,
I'd like to ask for comments or advice on a simple code for testing a
"subdict", i.e. check whether all items of a given dictionary are
present in a reference dictionary.
Sofar I have:
def is_subdict(test_dct, base_dct):
"""Test whether all
Hi all,
I'd like to ask for comments or advice on a simple code for testing a
"subdict", i.e. check whether all items of a given dictionary are
present in a reference dictionary.
Sofar I have:
def is_subdict(test_dct, base_dct):
"""Test whether all the items of test_dct are present in base_dct
18 matches
Mail list logo