Nest lists (create lists containing other lists) : Nested List « List « Python






Nest lists (create lists containing other lists)

Nest lists (create lists containing other lists)

q = [2, 3]
p = [1, q, 4]

print len(p)

print p[1]

print p[1][0]

p[1].append('xtra')

print p

print q

#p[1] and q really refer to the same object! 

           
       








Related examples in the same category

1.Demonstrates nested sequencesDemonstrates nested sequences
2.A list of lists: nested listA list of lists: nested list