Iterating Through Dictionary of Lists

Stefan Behnel stefan_ml at
Fri Sep 11 15:42:16 CEST 2009

JB wrote:
> I have created a small program that generates a project tree from a
> dictionary. The dictionary is of key/value pairs where each key is a
> directory, and each value is a list. The list have unique values
> corresponding to the key, which is a directory where each value in the
> list becomes a subdirectory.
> The question that I have is how to do this process if one of the
> unique values in the list is itself a dict. For example, in the
> "projdir" dict below, suppose the "Analysis" value in the list
> corresponding to the "Engineering" key was itself a dict and was
> assigned {'Analysis' : 'Simulink'} for example.

You might want to read up on recursion, i.e. a function calling itself.

You can find out if something is a dict like this:

	isinstance(x, dict)

or, if you know it really is a dict and not a subtype:

	type(x) is dict


More information about the Python-list mailing list