Creating Sublists from a “List”

前端 未结 5 2045
余生分开走
余生分开走 2021-01-24 08:21

I have a list in a file, looks like this

c4a24534,2434b375,e750c718, .... 

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

x         


        
5条回答
  •  一向
    一向 (楼主)
    2021-01-24 09:22

    Taking for granted that you've already parsed the file:

    x = [['c4a2', '4534'], ['2434', 'b375'], ['e750', 'c718']]
    i = [a[0] for a in x] # ['c4a2', '2434', 'e750']
    q = [a[1] for a in x] # ['4534', 'b375', 'c718']
    

    This takes the first and second element of each sub-list, and puts it into a new variable.

提交回复
热议问题