stacoverflow.comに答えがありました。多次元リストというのは、[1,2,3]ではなくて、[1,[2,3]のようにリストの中にリストがあるものを指します。リストのリストとか、ネストしたリストとか言われています。そういった多次元リストを1次元に平坦化したいときっ ...
Python でリストのリストを平らにする(あるいは連結する)なら、一番よいのは itertools.chain をつかう方法。 おなじことをするのに複数の書きかたがあるとき、基本的には短く書ける方法がよい。そしてすでに実装されているものがあるなら再発明は避けたい。
# also containing these special nodes. These child lists may have one or more children of their own, and so on, # to produce a multilevel data structure as shown in the example below. # Given the head ...
Flattens JSON objects in Python. flatten_json flattens the hierarchy in your object which can be useful if you want to force your objects into a table.