From efc50ddb1ddd9b355c13097bda10a5298f4f0a9e Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Tue, 10 Jan 2023 10:45:45 +0000 Subject: [PATCH] FP: Extra3 finished --- 1ano/fp/extra3/ex07.py | 2 ++ 1ano/fp/extra3/ex08.py | 7 +++++++ 1ano/fp/extra3/ex09.py | 8 ++++++++ 1ano/fp/extra3/ex10.py | 10 ++++++++++ 1ano/fp/extra3/ex11.py | 11 +++++++++++ 5 files changed, 38 insertions(+) create mode 100644 1ano/fp/extra3/ex07.py create mode 100644 1ano/fp/extra3/ex08.py create mode 100644 1ano/fp/extra3/ex09.py create mode 100644 1ano/fp/extra3/ex10.py create mode 100644 1ano/fp/extra3/ex11.py diff --git a/1ano/fp/extra3/ex07.py b/1ano/fp/extra3/ex07.py new file mode 100644 index 0000000..f6e69cd --- /dev/null +++ b/1ano/fp/extra3/ex07.py @@ -0,0 +1,2 @@ +def companyVolume(stocks, city): + return [(stock[0], stock[4]) for stock in stocks if stock[1] == city] diff --git a/1ano/fp/extra3/ex08.py b/1ano/fp/extra3/ex08.py new file mode 100644 index 0000000..f9a45a4 --- /dev/null +++ b/1ano/fp/extra3/ex08.py @@ -0,0 +1,7 @@ +def load(fname): + stocks_list = [] + with open(fname, 'r') as f: + for stock in f: + components = stock[:-1].split('\t') + stocks_list.append((components[0], components[1], float(components[2]), float(components[3]), int(components[4]))) + return stocks_list diff --git a/1ano/fp/extra3/ex09.py b/1ano/fp/extra3/ex09.py new file mode 100644 index 0000000..c48847f --- /dev/null +++ b/1ano/fp/extra3/ex09.py @@ -0,0 +1,8 @@ +def trinsPerMerchandise(trains): + content_dict = {} + for train, content in trains.items(): + for item in content: + if item[0] not in content_dict: + content_dict[item[0]] = set() + content_dict[item[0]].add(train) + return content_dict diff --git a/1ano/fp/extra3/ex10.py b/1ano/fp/extra3/ex10.py new file mode 100644 index 0000000..07ced4f --- /dev/null +++ b/1ano/fp/extra3/ex10.py @@ -0,0 +1,10 @@ +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: + t.remove(v) + return q diff --git a/1ano/fp/extra3/ex11.py b/1ano/fp/extra3/ex11.py new file mode 100644 index 0000000..eea9be7 --- /dev/null +++ b/1ano/fp/extra3/ex11.py @@ -0,0 +1,11 @@ +def onlyCaps(s): + # NOTE: ch.isupper() -> True if ch is uppercase. + if len(s) == 0: + return "" + if len(s) == 1: + return s if s.isupper() else "" + return s[0] + onlyCaps(s[1:]) if s[0].isupper() else onlyCaps(s[1:]) + + +print(onlyCaps("John Fitzgerald Kennedy")) +print(onlyCaps(""))