拆分列表中的每个字符串并存储在多个数组中 [英] Split each string in list and store in multiple arrays

查看:53
本文介绍了拆分列表中的每个字符串并存储在多个数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的列表: ['1 0 0','2 0.5 0.25','3 1 0.5','4 1.5 0.75']

I have a list that looks like this: ['1 0 0','2 0.5 0.25','3 1 0.5','4 1.5 0.75']

我想以这三个数组结尾: [1,2,3,4] [0,0.5,1,1.5] [0,0.25,0.5,0.75]

I want to end up with these three arrays: [1,2,3,4] and [0,0.5,1,1.5] and [0,0.25,0.5,0.75]

即我想要每个列表项的第一个值并将其存储在数组中,并对第二个和第三个值执行相同的操作.

i.e. I want the first value of each list item and store it in an array, and do the same with the second and third values.

我尝试过

for i in coordinates[:]:
    number,x,y=i.split(' ')

还尝试使用 number [] number.append 但这些似乎都不起作用

also tried using number[] and number.append but none of these seem to work

推荐答案

创建三个新列表,并进行输入:

Creating three new list, and going through a input:

input = ['1 0 0','2 0.5 0.25','3 1 0.5','4 1.5 0.75']
x_list = []
y_list = []
z_list = []

for i in input:
    x, y, z = i.split(' ')
    x_list.append(x)
    y_list.append(y)
    z_list.append(z)

这篇关于拆分列表中的每个字符串并存储在多个数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆