Hi all, I am trying to create a mini tagging for my widgets in which it will sets the visibility display accordingly to a list of checkboxes states.
For each of my checkboxes, it was initiallly returning a dictionary whenever it was toggled and my widgets are a list of nested dictionaries.
Currently I had the problem where my widgets will be set to hidden even if its other checkboxes are still True.
nested = {
'item01' : {
'k1' : ['1a', '1c'],
'k2' : ['2b']
},
'item02' : {
'k1' : ['1b', '1c'],
'k2' : ['2b', '2c'],
'k3' : ['3a']
},
'item03' : {
'k1' : ['1c'],
'k3' : ['3a', '3c']
}
}
# chk derives from user selections in which it is always changing
chk = {'k1' : '1c', 'k3' : '3c'}
ck = chk.keys()
cv = chk.values()
for nk, nv in nested.items ():
if nv.has_key(ck) and [i for i in nv[ck] if i == cv]:
print '{0} will be shown'.format(nk)
else:
print '>>> no matching keys/ values'
print '{0} will be hidden'.format(nk)
For example, ‘chk’ which is the checked options, while it will shown item01 and item03, and say if I checked off where ‘k1:1c’, item03 will be hidden despite ‘k3:3c’ option is still checked.
Any insights on how I can made this better?
Apologise in advance for the vague example…