tuples from lists
tjreedy at udel.edu
Sun Mar 9 21:41:56 CET 2003
"Bob Roberts" <bobnotbob at byu.edu> wrote in message
news:c4e6b17d.0303091212.4fee8ea9 at posting.google.com...
> I have a list of lists of lists. How can I turn that into a tuple
> tuples of tuples?
You have to work from inside out.
masterlist = [ [ [111,112], [121,122] ], [ [211,212], [221,222] ] ]
for i in range(len(masterlist)):
for j in range(len(masterlist[i])):
masterlist[i][j] = tuple(masterlist[i][j])
masterlist[i] = tuple(masterlist[i])
masterlist = tuple(masterlist)
#prints, cut and pasted
#(((111, 112), (121, 122)), ((211, 212), (221, 222)))
Terry J. Reedy
More information about the Python-list