Format list of list sub elements keeping structure.

Sayth Renshaw flebber.crue at gmail.com
Mon Jul 23 22:33:55 EDT 2018


> > 
> > for item in data:
> >     for elem in item:
> >         out = ("[{0}]").format(elem)
> >     print(out)
> 
> Hint: print implicitly adds a newline to the output string. So collect all the values of each sublist and print a line-at-time to output, or use the end= argument of Py3's print, or find another solution. Also remember that indention is significant in Python.

Thanks

Getting closer.

answer = []
for item in data:
    for elem in item:
        out = ("[{0}]").format(elem)
        answer.append(out)

print(answer)

Think I need to bring it in a list not an element of a list and process it.

Cheers

Sayth


More information about the Python-list mailing list