Betriebsumgebung
Xeon E5-2620 v4 (8 Kerne) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 und seine-devel
mpich.x86_64 3.1-5.el6 und seine-devel
gcc version 4.4.7 (Und Gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Verwende 1.
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
Python 3.6.0 on virtualenv
Verwandte: Python> Tupel> Doppeltupel in Einzel-Tupel konvertieren
Referenz: http://stackoverflow.com/questions/2961983/convert-multi-dimensional-list-to-a-1d-list-in-python Referenz: http://stackoverflow.com/questions/406121/flattening-a-shallow-list-in-python
test_python_170323e.py
import itertools
alist = [[3, 1, 4], [1, 5, 9], [2, 6, 5]]
print(alist)
# 1
res = [ flatten for inner in alist for flatten in inner ]
print(res)
# 2
res = itertools.chain(*alist)
res = list(res)
print(res)
Ergebnis
$ python test_python_170323e.py
[[3, 1, 4], [1, 5, 9], [2, 6, 5]]
[3, 1, 4, 1, 5, 9, 2, 6, 5]
[3, 1, 4, 1, 5, 9, 2, 6, 5]
Ich persönlich denke, dass itertools jetzt (23.03.2017) besser lesbar ist.
Recommended Posts