Something is really wrong with the design if data is a 3-level nested dict. This may be necessary, but there's no need for this method to know about implementation details like this - data should be a class with well defined interface that would be used here instead.