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

作者:顺便治水 时间:2023-12-30 13:10:04 

原始数据如下:


['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']

来源:https://blog.csdn.net/qq_38984928/article/details/89086095

标签:python,list,间隔,存储
0
投稿

猜你喜欢

  • python银行系统实现源码

    2022-08-09 16:05:20
  • 实操Python爬取觅知网素材图片示例

    2021-12-12 21:19:59
  • 关于tf.reverse_sequence()简述

    2022-05-23 03:05:08
  • 连接无法用于执行此操作。在此上下文中它可能已被关闭或无效

    2011-03-15 23:03:00
  • python实现自动化上线脚本的示例

    2021-02-01 05:14:49
  • vue.js $refs和$emit 父子组件交互的方法

    2024-04-30 10:19:11
  • python通用数据库操作工具 pydbclib的使用简介

    2024-01-24 14:24:16
  • asp 防盗链代码(彻底屏蔽迅雷,旋风,快车下载站内资源)

    2011-02-26 10:46:00
  • python如何重载模块实例解析

    2021-10-13 03:47:56
  • 浅谈Python响应式类库RxPy

    2021-12-24 12:44:26
  • JavaScript中创建原子的方法总结

    2023-06-29 12:22:14
  • Python中的Decorator装饰器的使用示例

    2023-07-02 10:37:44
  • Python 中@lazyprop 装饰器的用法

    2022-11-30 16:42:10
  • webpack学习教程之publicPath路径问题详解

    2023-07-16 06:09:52
  • Python PyInstaller库基本使用方法分析

    2022-03-19 16:29:46
  • Python如何利用Har文件进行遍历指定字典替换提交的数据详解

    2022-04-22 22:35:17
  • Python 中 Meta Classes详解

    2023-06-02 11:52:47
  • SQLite之Autoincrement关键字(自动递增)

    2024-01-13 20:16:29
  • 使用python实现ftp的文件读写方法

    2022-02-06 11:25:03
  • 用python对oracle进行简单性能测试

    2021-07-08 16:51:59
  • asp之家 网络编程 m.aspxhome.com