#I need to print if i found problem='FRAUDED BILL' or another phrase inside of those dict and print your respective key, (ex: EP1_2) for FRAUDED BILL
dict_ep = {'EP1_2':['FRAUDED BILL','IMPROPER BILLING - FRAUDED CARD (CARDS)','EMBEZZLEMENT','FRAUD'],
'EP1_4':['2nd COPY OF CONTRACT (CONSIGNEE)','ACCIDENT WITH DISPOSED VEHICLE'],
'EP1_6':['BANK STRIKE'],
'EP1_8':['ACCESS TO BALANCE AND CARD LIMIT','PAYMENT AGREEMENT']}
problem = ('frauded bill').upper()
for i in dict_ep:
if problem == dict_ep.keys():
print('EP found')
else:
print('EP no exist, try again!')
RESULTS:
EP no exist, try again!
EP no exist, try again!
EP no exist, try again!
EP no exist, try again!
CodePudding user response:
You can use any()
to test if the string is found in list:
dict_ep = {
"EP1_2": [
"FRAUDED BILL",
"IMPROPER BILLING - FRAUDED CARD (CARDS)",
"EMBEZZLEMENT",
"FRAUD",
],
"EP1_4": [
"2nd COPY OF CONTRACT (CONSIGNEE)",
"ACCIDENT WITH DISPOSED VEHICLE",
],
"EP1_6": ["BANK STRIKE"],
"EP1_8": ["ACCESS TO BALANCE AND CARD LIMIT", "PAYMENT AGREEMENT"],
}
problem = "frauded bill".upper()
for key, lst in dict_ep.items():
if any(problem in v for v in lst):
print("EP Found:", key)
else:
print("EP NOT Found:", key)
Prints:
EP Found: EP1_2
EP NOT Found: EP1_4
EP NOT Found: EP1_6
EP NOT Found: EP1_8