listtools.repeat_list_to_weight

abjad.tools.listtools.repeat_list_to_weight(l, weight, remainder='chop')

Repeat l until listtools.weight(result) compares correctly to weight as specified by remainder.

When remainder = 'chop' chop last number in output list to ensure that listtools.weight(result) equals weight exactly.

abjad> l = [5, 5, 5]
abjad> listtools.repeat_list_to_weight(l, 23)
[5, 5, 5, 5, 3]

When remainder = 'less' allow listtools.weight(result) to be less than or equal to weight.

abjad> l = [5, 5, 5]
abjad> repeat_list_to_weight(l, 23, remainder = 'less')
[5, 5, 5, 5]

When remainder = 'more' allow listtools.weight(result) to be greater than or equal to weight.

abjad> l = [5, 5, 5]
abjad> listtools.repeat_list_to_weight(l, 23, remainder = 'more')
[5, 5, 5, 5, 5]

Because listtools.weight(l) equals the sum of the absolute value of the elements in l, negative numbers in l cyclically repeat in the output of this function.

abjad> l = [-5, -5, 5]
abjad> listtools.repeat_list_to_weight(l, 23)
[-5, -5, 5, -5, -3]

Previous topic

listtools.repeat_list_to_length

Next topic

listtools.repeat_subruns_to_count

This Page