Skip to content

Commit

Permalink
Test für treeleaves
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Werner authored and smokey42 committed Apr 20, 2012
1 parent b12e531 commit b782b04
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions functional.py
Expand Up @@ -544,6 +544,10 @@ def treeleaves(is_branch, children_fn, root):
>>> listleaves = partial(treeleaves, delegate(isinstance, list), identity)
>>> list(listleaves([1, [2, 3, [4]], 5]))
[1, 2, 3, 4, 5]
>>> dictleaves = partial(treeleaves, delegate(isinstance, dict), \
lambda d: d.itervalues())
>>> sorted(dictleaves({'a': 1, 'b': {'c': {'d': 2, 'e': 3}}, 42: 4, 'f': 5}))
[1, 2, 3, 4, 5]
"""
nodes = treeseq(is_branch, children_fn, root)
return ifilter(complement(is_branch), nodes)
Expand Down

0 comments on commit b782b04

Please sign in to comment.