Created
May 17, 2024 10:23
-
-
Save leveryd/997dfd20665a056539f2e61216138961 to your computer and use it in GitHub Desktop.
笛卡尔积
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
def _get_match_rule(lef_element, element_list): | |
ret = [] | |
if len(element_list) == 1: | |
for i in element_list[0]: | |
new_left_element = copy.copy(lef_element) | |
new_left_element.append(i) | |
ret.append(new_left_element) | |
else: | |
for i in element_list[0]: | |
new_left_element = copy.copy(lef_element) | |
new_left_element.append(i) | |
for ii in _get_match_rule(new_left_element, element_list[1:]): | |
ret.append(ii) | |
return ret | |
print(_get_match_rule([], [[1, 2]])) | |
print(_get_match_rule([], [[1, 2], [3, 4]])) | |
print(_get_match_rule([], [[1, 2], [3, 4], [5, 6, 7]])) |
Author
leveryd
commented
May 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment