From e3219cd24d7edf27a083e571fb5b719986ef47fd Mon Sep 17 00:00:00 2001 From: HansBug Date: Wed, 25 Aug 2021 22:20:09 +0800 Subject: [PATCH] save the rise_demo_1.demo.py and rise_demo_2.demo.py --- .../advanced_usage/rise_demo_1.demo.py | 2 +- .../advanced_usage/rise_demo_2.demo.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/source/tutorials/advanced_usage/rise_demo_1.demo.py b/docs/source/tutorials/advanced_usage/rise_demo_1.demo.py index 0c86247ac1..c6801c2b1b 100644 --- a/docs/source/tutorials/advanced_usage/rise_demo_1.demo.py +++ b/docs/source/tutorials/advanced_usage/rise_demo_1.demo.py @@ -7,7 +7,7 @@ if __name__ == '__main__': t3 = TreeValue({'a': 6, 'b': 0, 'x': {'c': -5, 'd': 17}}) t4 = TreeValue({'a': 0, 'b': -17, 'x': {'c': -8, 'd': 15}}) t5 = TreeValue({'a': 3, 'b': 9, 'x': {'c': 11, 'd': -17}}) - st = {'first': (t1, t2), 'second': [t3, {'x': t4, 'y': t5}]} + st = {'first': (t1, t2), 'second': (t3, {'x': t4, 'y': t5})} tx = subside(st) # Rising process diff --git a/docs/source/tutorials/advanced_usage/rise_demo_2.demo.py b/docs/source/tutorials/advanced_usage/rise_demo_2.demo.py index 7c47e390f4..138782f30a 100644 --- a/docs/source/tutorials/advanced_usage/rise_demo_2.demo.py +++ b/docs/source/tutorials/advanced_usage/rise_demo_2.demo.py @@ -2,23 +2,28 @@ from treevalue import TreeValue, subside, rise if __name__ == '__main__': # The same demo as the subside docs - t1 = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) - t2 = TreeValue({'a': -14, 'b': 9, 'x': {'c': 3, 'd': 8}}) + t11 = TreeValue({'a': 1, 'b': 2, 'x': {'c': 3, 'd': 4}}) + t12 = TreeValue({'a': 3, 'b': 9, 'x': {'c': 15, 'd': 41}}) + t21 = TreeValue({'a': -14, 'b': 9, 'x': {'c': 3, 'd': 8}}) + t22 = TreeValue({'a': -31, 'b': 82, 'x': {'c': 47, 'd': 32}}) t3 = TreeValue({'a': 6, 'b': 0, 'x': {'c': -5, 'd': 17}}) t4 = TreeValue({'a': 0, 'b': -17, 'x': {'c': -8, 'd': 15}}) t5 = TreeValue({'a': 3, 'b': 9, 'x': {'c': 11, 'd': -17}}) - st = {'first': (t1, t2), 'second': [t3, {'x': t4, 'y': t5}]} + st = {'first': [(t11, t21), (t12, t22)], 'second': (t3, {'x': t4, 'y': t5})} tx = subside(st) # Rising process, with template # only the top-leveled dict will be extracted, # neither tuple, list nor low-leveled dict will not be extracted # because they are not defined in `template` argument - st2 = rise(tx, template={'first': None, 'second': [None, None]}) + st2 = rise(tx, template={'first': [None], 'second': (None, None)}) print('st2:', st2) - print("st2['first']:") - print(st2['first']) + print("st2['first'][0]:") + print(st2['first'][0]) + + print("st2['first'][1]:") + print(st2['first'][1]) print("st2['second'][0]:") print(st2['second'][0]) -- GitLab