Skip to content
Advertisement

What is the difference between bunch and dictionary type in python?

I found out that sklearn.utils.Bunch and dict work more or less the same. Like if there is a dict object say

dict_1 = {"a":1, "b":2}

and a bunch object say bunch

bunch_1 = Bunch(a=1, b=2)

both have the same set of behaviour.

Advertisement

Answer

Bunch is a subclass of the Dict class and supports all the methods as dict does. In addition, it allows you to use the keys as attributes.

b = Bunch(a=1, b=2)
>>> b['b']
2
>>> b.b
2

Read more here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement