A Classifier is initialized with a list of values separated by increasing numbers, serving as the boundaries
Question:
A Classifier is initialized with a list of values separated by increasing numbers, serving as the "boundaries" of the keys. I need hep with a Classifier class that will allow us to have "key-value dictionary" behavior, but with more flexibility.
class Classifier:
def __init__(self, values_and_boundaries):
def get(self, key):
def __str__(self):
s = Classifier(["negative",0,"non-negative"])
>>> s.get(-2) ## What kind of number is -2?
"negative"
>>> s.get(0) ## How about 0 (on a boundary)?
"non-negative"
>>> s.get(3) ## How about 3?
"non-negative"
>>> t = Classifier(["ice",32,"water",212,"steam"])
>>> t.get(31)
"ice"
>>> t.get(32) ## Boundary keys return values to the right
"water"
>>> t.get(33)
"water"
>>> t.get(68)
"water"
>>> t.get(212) ## Boundary keys return values to the right
"steam"
>>> t.get(1000)
"steam"
>>> print(s)
negative|0|non-negative
>>> print(t)
ice|32|water|212|steam
>>> s.delimiter = "+" ## s wants to go its own way
>>> print(s)
negative+0+non-negative
>>> print(t)
ice|32|water|212|steam
>>> Classifier.delimiter = "_" ## Change the class
>>> print(s) ## s doesn't get the change
negative+0+non-negative
>>> print(t) ## t gets the change
ice_32_water_212_steam
Management Accounting Information for Decision-Making and Strategy Execution
ISBN: 978-0137024971
6th Edition
Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young