From 4457deb5253f5d353d691dee07a467ca475778d4 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 6 Feb 2023 13:54:23 +0000 Subject: [PATCH] FP: Simplifications --- 1ano/1semestre/fp/aula08/interests.py | 2 +- 1ano/1semestre/fp/extra3/ex10.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/1ano/1semestre/fp/aula08/interests.py b/1ano/1semestre/fp/aula08/interests.py index a727ff6..e7676d4 100644 --- a/1ano/1semestre/fp/aula08/interests.py +++ b/1ano/1semestre/fp/aula08/interests.py @@ -21,7 +21,7 @@ def main(): print("a) Table of common interests:") commoninterests = {(p1, p2): interests[p1].intersection(interests[p2]) for p1 in interests for p2 in interests - if p1 != p2 and list(interests.keys()).index(p1) < list(interests.keys()).index(p2)} + if list(interests.keys()).index(p1) < list(interests.keys()).index(p2)} print(commoninterests) print("b) Maximum number of common interests:") diff --git a/1ano/1semestre/fp/extra3/ex10.py b/1ano/1semestre/fp/extra3/ex10.py index e6017a3..b5f7f35 100644 --- a/1ano/1semestre/fp/extra3/ex10.py +++ b/1ano/1semestre/fp/extra3/ex10.py @@ -20,11 +20,12 @@ def unload(t, m, q): for v in t[::-1]: if v[0] != m: continue - while v[1] > 0 and q > 0: - v[1] -= 1 - q -= 1 - if v[1] == 0: + if v[1] <= q: + q -= v[1] t.remove(v) + else: + v[1] -= q + q = 0 return q