1
def add_divisors(list_num):
final_list = []
divisors = []
for number in list_num:
for x in range(1, number+1):
if number % x == 0:
divisors.append(x)
final_list.extend(divisors.copy())
divisors.clear()
return final_list
print(add_divisors([3, 4, 6]))
Basically this program prints:
[1, 3, 1, 2, 4, 1, 2, 3, 6]
I would like to put the divisors of each number within a separate list for each, example:
[[1, 3], [1, 2, 4], [1, 2, 3, 6]]