May-04-2020, 06:32 AM
(May-04-2020, 06:22 AM)buran Wrote:data = {'caseA': ['Printers'], 'caseB': None, 'caseC': ['Printers', 'Computers'], 'caseD': None, 'caseE': None} item = 'Printers' result = ['affected' if item in (value or ()) else 'unaffected' for value in data.values()] print(', '.join(result))of course, it could also be oneliner.
Further reading: https://docs.python.org/3/library/stdtyp...and-or-not
Thanks buran for your swift reply!
Small addition, is there any way to get the name of the dictionary key in the result?
I mean....
Output:caseA affected, caseB unaffected, caseC affected, caseD unaffected, caseE unaffected