Minimales en Python
This commit is contained in:
22
src/Python/004.py
Normal file
22
src/Python/004.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
def minimales(lst: list[list[int]]) -> list[list[int]]:
|
||||||
|
res = []
|
||||||
|
for index, candidate in enumerate(lst):
|
||||||
|
candidate_set = set(candidate)
|
||||||
|
|
||||||
|
is_subset_of_another = any(
|
||||||
|
index != other_index and candidate_set <= set(other)
|
||||||
|
for other_index, other in enumerate(lst)
|
||||||
|
)
|
||||||
|
if is_subset_of_another:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not any(candidate_set == set(existing) for existing in res):
|
||||||
|
res.append(candidate)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
check = [[1, 3], [2, 3, 1], [3, 2, 5]]
|
||||||
|
print(minimales(check)) # [[2, 3, 1], [3, 2, 5]]
|
||||||
|
|
||||||
|
check = [[1, 3], [2, 3, 1], [3, 2, 5], [3, 1]]
|
||||||
|
print(minimales(check)) # [[2, 3, 1], [3, 2, 5]]
|
||||||
Reference in New Issue
Block a user