FP: Extra3 finished
This commit is contained in:
parent
73646c8b6b
commit
2db780c0f0
|
@ -0,0 +1,2 @@
|
|||
def companyVolume(stocks, city):
|
||||
return [(stock[0], stock[4]) for stock in stocks if stock[1] == city]
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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(""))
|
Loading…
Reference in New Issue