import copy from functools import reduce a = [1, 3, 5, 7, 9, 13, 15] b = [4, 5, 6, 8, 13] c = [5, 8, 13, 19] def get_common_factors(a, b, res=[]): _res = copy.deepcopy(res) if a and b: if a[0] == b[0]: _res.append(a[0]) a.pop(0) b.pop(0) else: target = min(a, b, key=lambda x: x[0]) target.pop(0) return get_common_factors(a, b, _res) else: return res def get_multiple_factors(arr): return reduce(lambda x, y: get_common_factors(x, y), arr) res = get_multiple_factors([a, b, c]) print(res)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question