回答編集履歴
1
追記
test
CHANGED
@@ -77,3 +77,77 @@
|
|
77
77
|
((((AAA,BBB),CCC),DDD), (EEE,FFF))
|
78
78
|
|
79
79
|
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
追記: 邪道
|
84
|
+
|
85
|
+
---
|
86
|
+
|
87
|
+
思い付いたので書きました。真似はしない方が良いです。
|
88
|
+
|
89
|
+
```Python
|
90
|
+
|
91
|
+
import ast
|
92
|
+
|
93
|
+
import re
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
src = r'((((AAA,BBB),CCC),DDD), (EEE,FFF))'
|
100
|
+
|
101
|
+
src = re.sub(r'(\w+)', r'"\1"', src)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
work = [ast.literal_eval(src)]
|
106
|
+
|
107
|
+
dst = []
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
while work:
|
112
|
+
|
113
|
+
tmp = work.pop()
|
114
|
+
|
115
|
+
dst.append(tmp)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
work += [e for e in tmp if isinstance(e, tuple)]
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
dst = [
|
126
|
+
|
127
|
+
str(e).replace('"', '').replace("'", "")
|
128
|
+
|
129
|
+
for e in reversed(dst)
|
130
|
+
|
131
|
+
]
|
132
|
+
|
133
|
+
print(*dst, sep='\n')
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/D3vRE8IVoels0cka)
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
(AAA, BBB)
|
144
|
+
|
145
|
+
((AAA, BBB), CCC)
|
146
|
+
|
147
|
+
(((AAA, BBB), CCC), DDD)
|
148
|
+
|
149
|
+
(EEE, FFF)
|
150
|
+
|
151
|
+
((((AAA, BBB), CCC), DDD), (EEE, FFF))
|
152
|
+
|
153
|
+
```
|