I have a Python dict that has keys as credit ratings, and the values are lists of integers for credit scores:
class Account:
credit_score_dict = {
'Excellent': [*range(830, 900)],
'Good': [*range(750, 830)],
'Decent': [*range(670, 750)],
'Bad': [*range(0, 670)],
}
def __init__(self, account_number, credit_score=None):
self.account_number = account_number
self.credit_score = credit_score
self.credit_rating = None
def get_credit_rating(self, credit_score):
self.credit_score = credit_score
for rating, score in self.credit_score_dict.items():
if score == credit_score:
self.credit_rating = self.credit_score_dict[rating]
I am having trouble assigning the credit rating (key) to the object using the credit score (value) that is passed to the get_credit_rating method. There may be an easier or more efficient way to do this. Any advice is appreciated!