tree representation of Python data

Dino dino at no.spam.ar
Sat Jan 21 17:58:50 EST 2023


you rock. Thank you, Stefan.

Dino

On 1/21/2023 2:41 PM, Stefan Ram wrote:
> ram at zedat.fu-berlin.de (Stefan Ram) writes:
>> def display_( object, last ):
>>     directory = object; result = ''; count = len( directory )
>>     for entry in directory:
>>         count -= 1; name = entry; indent = ''
>>         for c in last[ 1: ]: indent += '│   ' if c else '    '
>>         indent += '├──' if count else '└──' if last else ''
>>         result += '\n' + indent +( ' ' if indent else '' )+ name
>>         if directory[ entry ]:
>>             result += display_( directory[ entry ], last +[ count ])
>>     return result
> 
>    This ultimate version has some variable names made more speaking:
> 
> def display_( directory, container_counts ):
>      result = ''; count = len( directory )
>      for name in directory:
>          count -= 1; indent = ''
>          for container_count in container_counts[ 1: ]:
>              indent += '│   ' if container_count else '    '
>          indent += '├──' if count else '└──' if container_counts else ''
>          result += '\n' + indent +( ' ' if indent else '' )+ name
>          if directory[ name ]:
>              result += display_\
>              ( directory[ name ], container_counts +[ count ])
>      return result
> 
> 



More information about the Python-list mailing list