Used divmod function instead of div and modulus in in_groups for Array