Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
48
Task/Visualize-a-tree/Python/visualize-a-tree-1.py
Normal file
48
Task/Visualize-a-tree/Python/visualize-a-tree-1.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
Python 3.2.3 (default, May 3 2012, 15:54:42)
|
||||
[GCC 4.6.3] on linux2
|
||||
Type "copyright", "credits" or "license()" for more information.
|
||||
>>> help('pprint.pprint')
|
||||
Help on function pprint in pprint:
|
||||
|
||||
pprint.pprint = pprint(object, stream=None, indent=1, width=80, depth=None)
|
||||
Pretty-print a Python object to a stream [default is sys.stdout].
|
||||
|
||||
>>> from pprint import pprint
|
||||
>>> for tree in [ (1, 2, 3, 4, 5, 6, 7, 8),
|
||||
(1, (( 2, 3 ), (4, (5, ((6, 7), 8))))),
|
||||
((((1, 2), 3), 4), 5, 6, 7, 8) ]:
|
||||
print("\nTree %r can be pprint'd as:" % (tree, ))
|
||||
pprint(tree, indent=1, width=1)
|
||||
|
||||
|
||||
|
||||
Tree (1, 2, 3, 4, 5, 6, 7, 8) can be pprint'd as:
|
||||
(1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8)
|
||||
|
||||
Tree (1, ((2, 3), (4, (5, ((6, 7), 8))))) can be pprint'd as:
|
||||
(1,
|
||||
((2,
|
||||
3),
|
||||
(4,
|
||||
(5,
|
||||
((6,
|
||||
7),
|
||||
8)))))
|
||||
|
||||
Tree ((((1, 2), 3), 4), 5, 6, 7, 8) can be pprint'd as:
|
||||
((((1,
|
||||
2),
|
||||
3),
|
||||
4),
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8)
|
||||
>>>
|
||||
51
Task/Visualize-a-tree/Python/visualize-a-tree-2.py
Normal file
51
Task/Visualize-a-tree/Python/visualize-a-tree-2.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
>>> tree = "a",("b0",("c1","c2",("d",("ef","gh")),"c3",("i1","i2","i3",("jj"),"i4",("kk","m"))),"b1",("C1","C2",("D1",("E"),"D2","D3"),"C3"))
|
||||
>>> pprint(tree, width=1)
|
||||
('a',
|
||||
('b0',
|
||||
('c1',
|
||||
'c2',
|
||||
('d',
|
||||
('ef',
|
||||
'gh')),
|
||||
'c3',
|
||||
('i1',
|
||||
'i2',
|
||||
'i3',
|
||||
'jj',
|
||||
'i4',
|
||||
('kk',
|
||||
'm'))),
|
||||
'b1',
|
||||
('C1',
|
||||
'C2',
|
||||
('D1',
|
||||
'E',
|
||||
'D2',
|
||||
'D3'),
|
||||
'C3')))
|
||||
>>> copypasteoutput = ('a',
|
||||
... ('b0',
|
||||
... ('c1',
|
||||
... 'c2',
|
||||
... ('d',
|
||||
... ('ef',
|
||||
... 'gh')),
|
||||
... 'c3',
|
||||
... ('i1',
|
||||
... 'i2',
|
||||
... 'i3',
|
||||
... 'jj',
|
||||
... 'i4',
|
||||
... ('kk',
|
||||
... 'm'))),
|
||||
... 'b1',
|
||||
... ('C1',
|
||||
... 'C2',
|
||||
... ('D1',
|
||||
... 'E',
|
||||
... 'D2',
|
||||
... 'D3'),
|
||||
... 'C3')))
|
||||
>>> tree == copypasteoutput
|
||||
True
|
||||
>>>
|
||||
11
Task/Visualize-a-tree/Python/visualize-a-tree-3.py
Normal file
11
Task/Visualize-a-tree/Python/visualize-a-tree-3.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>>> pprint(tree, width=60)
|
||||
('a',
|
||||
('b0',
|
||||
('c1',
|
||||
'c2',
|
||||
('d', ('ef', 'gh')),
|
||||
'c3',
|
||||
('i1', 'i2', 'i3', 'jj', 'i4', ('kk', 'm'))),
|
||||
'b1',
|
||||
('C1', 'C2', ('D1', 'E', 'D2', 'D3'), 'C3')))
|
||||
>>>
|
||||
38
Task/Visualize-a-tree/Python/visualize-a-tree-4.py
Normal file
38
Task/Visualize-a-tree/Python/visualize-a-tree-4.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
>>> mixedtree = ['a', ('b0', ('c1', 'c2', ['d', ('ef', 'gh')], 'c3', ('i1', 'i2',
|
||||
... 'i3', 'jj', 'i4', ['kk', 'm'])), 'b1', ('C1', 'C2', ('D1', 'E',
|
||||
... 'D2', 'D3'), 'C3'))]
|
||||
>>> pprint(mixedtree, width=1)
|
||||
['a',
|
||||
('b0',
|
||||
('c1',
|
||||
'c2',
|
||||
['d',
|
||||
('ef',
|
||||
'gh')],
|
||||
'c3',
|
||||
('i1',
|
||||
'i2',
|
||||
'i3',
|
||||
'jj',
|
||||
'i4',
|
||||
['kk',
|
||||
'm'])),
|
||||
'b1',
|
||||
('C1',
|
||||
'C2',
|
||||
('D1',
|
||||
'E',
|
||||
'D2',
|
||||
'D3'),
|
||||
'C3'))]
|
||||
>>> pprint(mixedtree, width=60)
|
||||
['a',
|
||||
('b0',
|
||||
('c1',
|
||||
'c2',
|
||||
['d', ('ef', 'gh')],
|
||||
'c3',
|
||||
('i1', 'i2', 'i3', 'jj', 'i4', ['kk', 'm'])),
|
||||
'b1',
|
||||
('C1', 'C2', ('D1', 'E', 'D2', 'D3'), 'C3'))]
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue