Checking for sub dictionary in a main dictionary

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    #1

    Checking for sub dictionary in a main dictionary

    Hi,

    I would like to check for the sub-dictionary availability in main dictionary,with out using loops.

    Say
    l1 ={1:100,2:200,4 :500,6:900}
    l2 = {2:200,6:900}

    O/P:

    if the sub-dictionary is subset of main dictionary.It should say TRUE

    -PSB
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by psbasha
    Hi,

    I would like to check for the sub-dictionary availability in main dictionary,with out using loops.

    Say
    l1 ={1:100,2:200,4 :500,6:900}
    l2 = {2:200,6:900}

    O/P:

    if the sub-dictionary is subset of main dictionary.It should say TRUE

    -PSB
    >>> l1 ={1:100,2:200,4 :500,6:900}
    >>> l2 = {2:200,6:900}
    >>> bool(set(l1.ite ms()).intersect ion(set(l2.item s())))
    True
    >>>

    Comment

    Working...