たくさんのコレクションから15枚の画像を選びたいです。画像の数は、そのコレクションの画像の割合によって異なります。
私のコードは次のとおりです。
image_counts = [16, 2, 14]
total_images = 0
for i in image_counts:
total_images += i
proportions = [1.0 * i / total_images for i in image_counts]
counts = [int( round( 15 * i)) for i in proportions]
ただし、[8, 1, 7]
丸めにより、出力は 16 になります。合計するとちょうど 15 になるリストを取得するにはどうすればよいですか?