listtools.flatten

abjad.tools.listtools.flatten(l, ltypes=(<type 'list'>, <type 'tuple'>), depth=2147483647)

Flatten nested lists l. Return a 0-depth list or tuple. Set optional depth keyword set to positive integer. Keyword controls depth to which the function operates. Based on Mike C. Fletcher’s flatten.

abjad> t = [1, [2, 3, [4]], 5, [6, 7, [8]]]
abjad> listtools.flatten(t)
[1, 2, 3, 4, 5, 6, 7, 8]
abjad> listtools.flatten(t, depth = 0)
[1, [2, 3, [4]], 5, [6, 7, [8]]]
abjad> listtools.flatten(t, depth = 1)
[1, 2, 3, [4], 5, 6, 7, [8]]
abjad> listtools.flatten(t, depth = 2)
[1, 2, 3, 4, 5, 6, 7, 8]

Previous topic

listtools.difference_series

Next topic

listtools.get_cyclic

This Page