Skip to content

Instantly share code, notes, and snippets.

@chen-jia-hao
Created August 22, 2022 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chen-jia-hao/94a1fbfecd402e838496a0331d65fa52 to your computer and use it in GitHub Desktop.
Save chen-jia-hao/94a1fbfecd402e838496a0331d65fa52 to your computer and use it in GitHub Desktop.
多数组取值计算
from functools import reduce
a = [1, 2, 3, 4, 5, 6, 7, 8]
b = [1, 2, 3, 4, 5, 6, 7, 8]
c = [1, 2, 3, 4, 5, 6, 7, 8]
target = 16
mixin_total = []
for i in a:
for j in b:
for k in c:
mixin_total.append(tuple([i, j, k]))
print(mixin_total)
def compare(its):
ret = reduce(lambda m, n: m + n, its)
return ret == target
ret_total = filter(compare, mixin_total)
print(list(ret_total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment