慕田峪9158850
写一个包装器。def wrapper_combinations_with_replacement(iterable, r): comb = combinations_with_replacement(iterable, r) for item in comb: yield list(item)现在你有了一个列表的列表。a = 1b = 2c = 3d = 4comb = wrapper_combinations_with_replacement([a, b, c, d], 2)for i in list(comb): print(i)结果是:[1, 1][1, 2][1, 3][1, 4][2, 2][2, 3][2, 4][3, 3][3, 4][4, 4]或者使用listlist(wrapper_combinations_with_replacement([a, b, c, d], 2))结果:[[1, 1], [1, 2], [1, 3], [1, 4], [2, 2], [2, 3], [2, 4], [3, 3], [3, 4], [4, 4]]
动漫人物
comb_list = [list(combination) for combination in (list(comb))]这将为您提供一个数组形式的组合列表for array_combination in comb_list: print(array_combination)Output:> [1, 1] [1, 2] [1, 3] [1, 4] [2, 2] [2, 3] [2, 4] [3, 3] [3, 4] [4, 4]