Fundamentals
Arrays
Strings
class FindTRex: """Find Trex class.""" def __init__(self, lst): """Initialize attribute""" self.lst = lst def find_trex(self): """Returns True if 'tyrannosaurus' is in self.lst, False if not.""" return "tyrannosaurus" in self.lst
- class FindTRex:
- """Find Trex class."""
- def __init__(self, lst):
- """Initialize attribute"""
- self.lst = lst
- def find_trex(self):
- """Returns True if 'tyrannosaurus' is in self.lst, False if not."""
return self.lst.__contains__('tyrannosaurus')- return "tyrannosaurus" in self.lst
from statistics import mean import operator cases = { "Behind Milestone": operator.lt, "At Milestone": operator.eq, "Beyond Milestone": operator.gt, } def compute_progress(trainee, milestone): trainee_score = mean(trainee) milestone_score = mean(milestone) return next(progress for progress, test in cases.items() if test(trainee_score, milestone_score))
calc = lambda x: sum(x) // len(x)- from statistics import mean
- import operator
- cases = {
'Behind Milestone' : lambda t, m: calc(t) < calc(m),'At Milestone' : lambda t, m: calc(t) == calc(m),'Beyond Milestone' : lambda t, m: calc(t) > calc(m)- "Behind Milestone": operator.lt,
- "At Milestone": operator.eq,
- "Beyond Milestone": operator.gt,
- }
compute_progress = lambda t, m: next((k for k,v in cases.items() if v(t, m)))- def compute_progress(trainee, milestone):
- trainee_score = mean(trainee)
- milestone_score = mean(milestone)
- return next(progress for progress, test in cases.items() if test(trainee_score, milestone_score))