python list数据等间隔抽取并新建list存储的例子

yipeiwu_com6年前Python基础

原始数据如下:

['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存储的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

django富文本编辑器的实现示例

django富文本编辑器的实现示例

最近一段时间都在学django,现在的网站基本都要使用到富文本编辑器,今天就记录下使用django的管理后台的一个富文本编辑器的第三方库 DjangoUeditor 使用方法 1.安装...

Python操作Sql Server 2008数据库的方法详解

Python操作Sql Server 2008数据库的方法详解

本文实例讲述了Python操作Sql Server 2008数据库的方法。分享给大家供大家参考,具体如下: 最近由于公司的一个项目需要,需要使用Sql Server 2008数据库,开发...

Python实现设置windows桌面壁纸代码分享

每天换一个壁纸,每天好心情。 # -*- coding: UTF-8 -*- from __future__ import unicode_literals import Ima...

wxPython绘图模块wxPyPlot实现数据可视化

wxPython绘图模块wxPyPlot实现数据可视化

本文实例为大家分享了wxPython绘图模块wxPyPlot实现数据可视化的具体代码,供大家参考,具体内容如下 #-*- coding: utf-8 -*- #########...

python 简单的多线程链接实现代码

服务端: #!/usr/bin/env import SocketServer class myMonitorHandler(SocketServer.BaseRequestHand...