python - 如何根据类型分隔列表值 - Python
问题描述
从包含整数、字符串和浮点数的列表中,创建三个列表以分别存储它们。
请帮助我如何根据类型分隔列表值。
解决方案
您可以使用类型。
test = [3, "hello", 2.4]
int_array = []
string_array = []
float_array = []
for value in test:
check = type(value)
if check == int:
int_array.append(value)
elif check == str:
string_array.append(value)
elif check == float:
float_array.append(value)
推荐阅读
- angularjs - AngularJS如何将组件双向绑定转换为单向绑定
- django - Django 单元测试不会更新 BooleanField
- python - 多个列表之间的时间差
- azure - 在 Azure 容器实例中,可以重复使用容器组还是每个部署都使用自己的容器组?
- read-write - 在读/写操作期间文件的当前位置保存在哪里?
- video-streaming - 如何从电子流式传输视频?
- vba - 我究竟做错了什么?使用 Excel VBA 删除重复项
- java - 如何在 JSP 中获取类公共字符串?
- kotlin - Kotlin - 如何从字符串日期获取时间(“HH:mm”)
- javascript - 如何使用 javascript 检测移动设备屏幕已关闭