原始数据如下:
['e3cd', 'e547', 'e63d', '0ffd', 'e39b', 'e539', 'e5be', '0dd2', 'e3d6', 'e52e', 'e5f8', '0000', 'e404', 'e52b', 'e63d', '0312', 'e38b']
将其分割为4路数据,分别存储在fetal1、fetal2、mother1、ECG的列表中,各列表对齐,不能整除于4的数据舍去,操作如下:
da = ['e3cd', 'e547', 'e63d', '0ffd', 'e39b', 'e539', 'e5be', '0dd2', 'e3d6', 'e52e', 'e5f8', '0000', 'e404', 'e52b', 'e63d', '0312', 'e38b'] k = 0 num1 = 0 fetal1 = [] fetal2 = [] mother1 = [] ECG = [] for k in range(len(da)-int(len(da) % 4)): if num1 == 1: fetal2.append(da[k]) elif num1 == 2: mother1.append(da[k]) elif num1 == 3: ECG.append(da[k]) else: num1 = 0 fetal1.append(da[k]) num1 += 1 print("fetal1:", fetal1) print("fetal2:", fetal2) print("mother1", mother1) print("ECG:", ECG)
运行结果如下:
fetal1: ['e3cd', 'e39b', 'e3d6', 'e404'] fetal2: ['e547', 'e539', 'e52e', 'e52b'] mother1 ['e63d', 'e5be', 'e5f8', 'e63d'] ECG: ['0ffd', '0dd2', '0000', '0312']
以上这篇python list数据等间隔抽取并新建list存储的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。