Hi all, I am trying to do a 'skimming' or reduction method in dictionaries in which it will returns me a set of results from a given set of condition.
However my current method is more of an additive where it will simply lists me any items that fulfills any one of the condition. Currently while it seems to be not working if there is only one key and one list item.. # Give me items that are menuA/a100 + menuB/b100, or menuA/a100 + menuB/b200 conditions = {'menuA':['a200']} my_items = [ {'item01' : {'menuA': ['a100'], 'menuB': ['b200']}}, {'item02' : {'menuA': ['a200'], 'menuB': ['b200'], 'menuC' : ['c100']}}, {'item03' : {'menuA': ['a100'], 'menuB': ['b200']}}, {'item04' : {'menuA': ['a100', 'a200']}}, {'item05' : {'menuB': ['b100'], 'menuC': ['c100']}} ] result = [] for m in my_items: for mk, mv in m.items(): all_conditions_met = len(conditions) == len(mv) #False for condition in conditions: if condition in mv: all_conditions_met &= bool((set(mv[condition]) & set(conditions[condition]))) ############### # Tried the following but it will fail if given condition # eg. conditions = {'menuA': ['a100', 'a200'], 'menuB': ['b200']} # where it should return me ['item01', 'item03'] but it gives me [] instead... # all_conditions_met &= bool((set(mv[condition]) & set(conditions[condition]))) & (len(mv[condition]) == len(conditions[condition])) ############### else: all_conditions_met = False break if all_conditions_met: result.append(mk) print result # 'item04' In my above example, given the condition {'menuA':['a200']}, it should not be returning me any results as there are no items that consists only of {'menuA':['a200']} but yet it return me an item - closest to the given condition… The idea behind this is to simply returns me items based on the conditions. Could someone kindly share some insights on this matter? -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3eac4a92-ce87-4264-ad5a-e919aeef59a7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.