Checking if a variable is a dictionary
Martin Marcher
martin at marcher.name
Thu Mar 6 09:26:27 EST 2008
On Thu, Mar 6, 2008 at 2:06 PM, Guillermo
<guillermo.listas at googlemail.com> wrote:
> >What makes you say you "need" to know this ? Except for a couple corner
> >cases, you usually don't need to care about this. If you told us more
> >about the actual problem (instead of asking about what you think is the
> >solution), we might be of more help...
>
> I want to iterate recursively a dictionary whose elements might be
> strings or nested tuples or dictionaries and then convert values to a
> tagged format according to some rules.
just do so, if it's not a dict you can always catch the exception,
then handle tuples (or the exception), then strings which should work
always (of course also error handling here according to your needs)
> I'm just designing the algorithm, but I think Python dictionaries can
> hold any kind of sequence?
python dicts can hold any kind of object (as a value). What you can't
do is have a list as the key, but that is easily circumvented by using
a tuple (or any other immutable type).
hth
martin
--
http://tumblr.marcher.name
https://twitter.com/MartinMarcher
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher
You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.
More information about the Python-list
mailing list