How to test for type or instance of dict_values?
Terry Reedy
tjreedy at udel.edu
Thu Nov 17 12:08:58 EST 2016
On 11/17/2016 9:57 AM, Thorsten Kampe wrote:
> The code in question is part of an attempt to get the dimensions of
> multi-dimensional lists, the `isinstance` is there in order to
> exclude strings.
You can do the exclusion directly.
>
> """
> def dim(seq):
> dimension = []
> while isinstance(seq, (list, tuple)):
while not isinstance(seq, str) # or (str, bytes, ...)
> dimension.append(len(seq))
> try:
> seq = seq[0]
> except IndexError: # sequence is empty
> break
> return dimension
> """
>
> Thorsten
>
--
Terry Jan Reedy
More information about the Python-list
mailing list