FP: Extra3 finished

This commit is contained in:
TiagoRG 2023-01-10 10:45:45 +00:00
parent 73646c8b6b
commit 2db780c0f0
5 changed files with 38 additions and 0 deletions

2
1ano/fp/extra3/ex07.py Normal file
View File

@ -0,0 +1,2 @@
def companyVolume(stocks, city):
return [(stock[0], stock[4]) for stock in stocks if stock[1] == city]

7
1ano/fp/extra3/ex08.py Normal file
View File

@ -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

8
1ano/fp/extra3/ex09.py Normal file
View File

@ -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

10
1ano/fp/extra3/ex10.py Normal file
View File

@ -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

11
1ano/fp/extra3/ex11.py Normal file
View File

@ -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(""))