Tree datastructures: Difference between revisions

Content added Content deleted
(→‎{{header|AppleScript}}: Rethought use of glfing (see talk page); but please read new notes section of task please.)
(→‎Procedural: golf->troll)
Line 1,037: Line 1,037:


<lang python>from pprint import pprint as pp
<lang python>from pprint import pprint as pp
from collections import namedtuple


def to_indent(node, depth=0, flat=None):
def to_indent(node, depth=0, flat=None):
Line 1,066: Line 1,065:
print('Start Nest format:')
print('Start Nest format:')
nest = ('RosettaCode', [('rocks', [('code', []), ('comparison', []), ('wiki', [])]),
nest = ('RosettaCode', [('rocks', [('code', []), ('comparison', []), ('wiki', [])]),
('mocks', [('golfing', [])])])
('mocks', [('trolling', [])])])
pp(nest, width=25)
pp(nest, width=25)


Line 1,088: Line 1,087:
('wiki', [])]),
('wiki', [])]),
('mocks',
('mocks',
[('golfing', [])])])
[('trolling', [])])])


... To Indent format:
... To Indent format:
Line 1,097: Line 1,096:
(2, 'wiki'),
(2, 'wiki'),
(1, 'mocks'),
(1, 'mocks'),
(2, 'golfing')]
(2, 'trolling')]


... To Nest format:
... To Nest format:
Line 1,106: Line 1,105:
('wiki', [])]),
('wiki', [])]),
('mocks',
('mocks',
[('golfing', [])])])</pre>
[('trolling', [])])])</pre>


===Functional===
===Functional===