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

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


Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python class Classifier delimiter def initself valuesandboundaries selfmapping key None fo... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!