Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

python - Creating Sublists from a "List"

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'

and

 q=
'4534'
'b375'
'c718'

I have tried :

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...