I create the following OrderedDict:
import collections
class obj1():
def __init__(self):
self.aa = 22
self.bb = 23
class obj2():
def __init__(self):
self.dd = 22
self.ee = 23
my_test = collections.OrderedDict()
my_test['1'] = obj1
my_test['2'] = obj1
my_test['3'] = obj1
my_test['4'] = obj2
and this is the outcome:
my_test
Out[41]:
OrderedDict([('1', __main__.obj1),
('2', __main__.obj1),
('3', __main__.obj1),
('4', __main__.obj2)])
As it can be noticed, there are two types of object: obj1
and obj2
. I would like to know if it is possible to know the number of obj1
(i.e. 3) in that OrderedDict structure.
I was thinking about a cycle over all the tuples. This approach has, however, two problems:
- I do not know how to extract the object name,
- it seems no so straightforward.