from itertools import chain
chain(*iterables)
將多個可迭代對象進行合併,相當於如下代碼:
def chain(*iterables):
# chain('XYZ', 'DEF') --> X Y Z D E F
for it in iterables:
for element in it:
yield element
############ ex.01
ops={}
ops['missing'] = ['gx_mean','gy_mean']
ops['collinear'] = ['gx_skew','gy_skew',]
ops['zero_importance'] = ['gx_kurt','gy_kurt']
ops['low_importance'] = ['gx_range','gy_range']
from itertools import chain
all_identified = set(list(chain(*list(ops.values()))))
all_identified
Out[112]:
{'gx_kurt',
'gx_mean',
'gx_range',
'gx_skew',
'gy_kurt',
'gy_mean',
'gy_range',
'gy_skew'}
ops['missing'] = ['gx_mean','gy_mean','gz_mean','ax_mean','ay_mean','az_mean',
'gx_std','gy_std','gz_std','ax_std','ay_std','az_std']