0

What's the meaning of

def tree():
    return defaultdict(tree)

t = tree()

How can I do it without function?

t = defaultdict() 

It's not the same.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Alex
  • 11
  • 4
  • 2
    Yes, it's not the same. What do you want to achieve, exactly? – mkrieger1 Sep 14 '21 at 08:18
  • `tree` is a function which, when called, returns a defaultdict which calls `tree` for non-existent values, i.e. creates a defaultdict which uses `tree` for each non-existent value. Since this definition is recursive, it's not really possible to make it a one-liner. – deceze Sep 14 '21 at 08:22
  • the same behavior @mkrieger1 – Alex Sep 14 '21 at 09:00

0 Answers0