I'm not sure doing this in a separate function makes the code any clearer. And if you think it really does, it should be refactored from other places similar logic is used (e.g. https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/cross_validation.py#L656, https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_extraction/text.py#L757, https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/feature_extraction/image.py#L207), and put into a util function. I can see reasons to do so. Most notably you can't just check for `isinstance(x, int)` as you have done, but should use `isinstance(x, (numbers.Integral, np.integer))`. But it belongs in a separate PR.