running split () to form a list within another list

4

I have the following list:

[['a:/, b:/, w:/, g:/, f:/, d:/Downloads/Torrent/End, x:/files.2t, y:/files.1t'], ['d:/Dropbox/project/rato_bat'], ['data']]

But I wanted it to be a list inside another list because I did this:

    for a in lldir:
        for b in a:
           b = b.split(', ')

Would it be possible to do this in a row and assign it to a variable?

    
asked by anonymous 26.07.2016 / 20:41

1 answer

4

You want something like:

novo_conjunto = []
for a in lldir:
    nova_lista = [] 
    for b in a:
       nova_lista.append(b.split(', '))
    novo_conjunto.append(nova_lista)
a = novo_conjunto

If you want one line only:

a = [[elemento.split()] for elemento in lista] for lista in a]

If you want a single list with all the directory entries, all the sub-lists of the first entry:

diretorios = []
for lista in a:
    for elemento in lista:
        for diretorio in elemento.split(","):
            diretorio.append(diretorio.strip())
    
26.07.2016 / 20:51