diff --git a/python-package/lightgbm/dask.py b/python-package/lightgbm/dask.py index 8d6bafc45a4e..64b8dc7bd575 100644 --- a/python-package/lightgbm/dask.py +++ b/python-package/lightgbm/dask.py @@ -288,15 +288,16 @@ def _train( data_parts = _split_to_parts(data=data, is_matrix=True) label_parts = _split_to_parts(data=label, is_matrix=False) parts = [{'data': x, 'label': y} for (x, y) in zip(data_parts, label_parts)] + n_parts = len(parts) if sample_weight is not None: weight_parts = _split_to_parts(data=sample_weight, is_matrix=False) - for i in range(len(parts)): + for i in range(n_parts): parts[i]['weight'] = weight_parts[i] if group is not None: group_parts = _split_to_parts(data=group, is_matrix=False) - for i in range(len(parts)): + for i in range(n_parts): parts[i]['group'] = group_parts[i] # Start computation in the background