从“列表"创建子列表 [英] Creating Sublists from a "List"

查看:42
本文介绍了从“列表"创建子列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件中有一个列表,看起来像这样

I have a list in a file, looks like this

c4a24534,2434b375,e750c718, .... 

我已在,"处拆分并带来以下列表.

I have split at "," and brought the below list.

x=
['c4a2', '4534'] 
['2434', 'b375']
['e750', 'c718']

我需要从中制作两个新列表

I need to make two new lists out of this

i=
'c4a2'
'2434'
'e750'

 q=
'4534'
'b375'
'c718'

我试过了:

for x in line:
    x = [i.split() for i in x]

有了这个,我正在拆分 x .这给了我i"部分,但我如何得到其余的q"?

With this I am splitting the x .This gives me "i" part but how do i get the rest "q" ?

推荐答案

如果您已经阅读了列表列表,请使用 zip() 将列转换为行:

If you have read a list of lists, use zip() to turn columns into rows:

file_result = [
    ['19df', 'b35d']
    ['fafa', 'bbaf']
    ['dce9', 'cf47']
]

a, b = zip(*file_result)

这篇关于从“列表"创建子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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