Michele De Stefano's C++ Utilities
list_usage.pycmd
1 // list_usage.pycmd
2 //
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 
8 /**
9  * \example list_usage.pycmd
10  *
11  * Shows the usage of the list_usage extension from the Python prompt.
12  */
13 
14 mds_utils::python::list usage example from the Python prompt:
15 
16 
17 >>> import list_usage as lu
18 >>> l = lu.create_list((1,1.1,2.2,'aa',('bb','h'),[1.2,'fff','t']))
19 Built list length: 6
20 >>> l
21 [1, 1.1, 2.2, 'aa', ('bb', 'h'), [1.2, 'fff', 't']]
22 >>> l2 = lu.create_from_fusion()
23 >>> l2
24 [1, 2.2, 'aaa']
25 >>> l3 = lu.create_from_seq((3.4,'hh',[(1,2),('o',9),['p',90]]))
26 >>> l3
27 [3.4, 'hh', [(1, 2), ('o', 9), ['p', 90]]]
28 >>> l4 = lu.create_from_seq2([1,10,'fgh'])
29 >>> l4
30 [1, 10, 'fgh']
31 >>> lu.access_element(l,2)
32 2.2
33 >>> lu.access_element(l,-2)
34 ('bb', 'h')
35 >>> lu.access_element(l,-1)
36 [1.2, 'fff', 't']
37 >>> lu.access_element(l,10)
38 Traceback (most recent call last):
39  File "<stdin>", line 1, in <module>
40 RuntimeError: Cannot access element 10
41  >>> lu.set_element(l,-2,'aaa')
42 >>> l
43 [1, 1.1, 2.2, 'aa', 'aaa', [1.2, 'fff', 't']]
44 >>> lu.set_element(l,1,'0000')
45 >>> l
46 [1, '0000', 2.2, 'aa', 'aaa', [1.2, 'fff', 't']]
47 >>> lu.append_element(l,l2)
48 >>> l
49 [1, '0000', 2.2, 'aa', 'aaa', [1.2, 'fff', 't'], [1, 2.2, 'aaa']]
50 >>> lu.insert_element(l,2,l3)
51 >>> l
52 [1, '0000', [3.4, 'hh', [(1, 2), ('o', 9), ['p', 90]]], 2.2, 'aa', 'aaa', [1.2, 'fff', 't'], [1, 2.2, 'aaa']]
53 >>> lu.del_element(l,2)
54 >>> l
55 [1, '0000', 2.2, 'aa', 'aaa', [1.2, 'fff', 't'], [1, 2.2, 'aaa']]
56 >>> lu.del_element(l,-1)
57 >>> l
58 [1, '0000', 2.2, 'aa', 'aaa', [1.2, 'fff', 't']]
59 >>> lu.sort_list(l)
60 >>> l
61 [1, 2.2, [1.2, 'fff', 't'], '0000', 'aa', 'aaa']
62 >>> lu.reverse_list(l)
63 >>> l
64 ['aaa', 'aa', '0000', [1.2, 'fff', 't'], 2.2, 1]
65 >>> l5 = lu.dup_list(l)
66 >>> l5
67 ['aaa', 'aa', '0000', [1.2, 'fff', 't'], 2.2, 1]
68 >>> l5[0] = 1
69 >>> l5
70 [1, 'aa', '0000', [1.2, 'fff', 't'], 2.2, 1]
71 >>> l
72 [1, 'aa', '0000', [1.2, 'fff', 't'], 2.2, 1]
73 >>> l6 = lu.dup_list2(l5)
74 >>> l6
75 [1, 'aa', '0000', [1.2, 'fff', 't'], 2.2, 1]
76 >>> l6[2] = 'bbb'
77 >>> l6
78 [1, 'aa', 'bbb', [1.2, 'fff', 't'], 2.2, 1]
79 >>> l5
80 [1, 'aa', 'bbb', [1.2, 'fff', 't'], 2.2, 1]
81 >>> l
82 [1, 'aa', 'bbb', [1.2, 'fff', 't'], 2.2, 1]
83 >>> lu.append_double(l)
84 >>> l
85 [1, 'aa', 'bbb', [1.2, 'fff', 't'], 2.2, 1, 1.1]
86