This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Student = dc.make_dataclass( | |
| cls_name='Student', | |
| fields=[ | |
| ('firstname', str), | |
| ('lastname', str), | |
| ('student_no', str) | |
| ], | |
| namespace={ | |
| 'greeting': lambda self: f'Hello, {self.firstname} {self.lastname}!' | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Person: | |
| def __init__(self, firstname, lastname, age): | |
| self.firstname = firstname | |
| self.lastname = lastname | |
| self.age = age | |
| def __repr__(self): | |
| return f"Person(firstname='{self.firstname}', lastname='{self.lastname}', age={self.age})" | |
| def __eq__(self, other): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | s = """Gur Mra bs Clguba, ol Gvz Crgref | |
| Ornhgvshy vf orggre guna htyl. | |
| Rkcyvpvg vf orggre guna vzcyvpvg. | |
| Fvzcyr vf orggre guna pbzcyrk. | |
| Pbzcyrk vf orggre guna pbzcyvpngrq. | |
| Syng vf orggre guna arfgrq. | |
| Fcnefr vf orggre guna qrafr. | |
| Ernqnovyvgl pbhagf. | |
| Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import re | |
| class Employee: | |
| def __init__(self, name, year_joined): | |
| self.name = name | |
| self.year_joined = year_joined | |
| @classmethod | |
| def from_string(cls, string): | |
| name = re.search('I am (.*?) ', string).group(1) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Employee: | |
| def __init__(self, name, year_joined): | |
| self.name = name | |
| self.year_joined = year_joined | |
| @staticmethod | |
| def calc_year(year_joined, year_now): | |
| length = year_now - year_joined | |
| if length > 0: | |
| return f'{length} years' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def calc_year(year_joined, year_now): | |
| length = year_now - year_joined | |
| if length > 0: | |
| return f'{length} years' | |
| else: | |
| return 'less than one year' | |
| class Employee: | |
| def __init__(self, name, year_joined): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from datetime import datetime | |
| class Employee: | |
| def __init__(self, name, year_joined): | |
| self.name = name | |
| self.year_joined = year_joined | |
| def calc_year(self, year_joined, year_now): | |
| length = year_now - year_joined | |
| if length > 0: | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def max_vote_dynamic_planning(states, total_days): | |
| dp_matrix = [[0 for days_left in range(total_days + 1)] for index in range(len(states) + 1)] | |
| for index in range(1, len(states) + 1): | |
| for days_left in range(1, total_days + 1): | |
| if states[index-1]['days'] <= days_left: # If we have enough days left | |
| votes_if_go = dp_matrix[index-1][days_left - states[index-1]['days']] + states[index-1]['votes'] | |
| votes_if_not_go = dp_matrix[index-1][days_left] | |
| # Save the maximum votes into cache | |
| dp_matrix[index][days_left] = max(votes_if_go, votes_if_not_go) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def max_vote_recursive(states, days_left, index): | |
| # Terminating conditions | |
| if len(states) == 0 or index >= len(states) or days_left <= 0: | |
| return 0 | |
| # If we have enough days, go to this state | |
| votes_if_go = 0 | |
| if states[index]['days'] <= days_left: | |
| votes_if_go = states[index]['votes'] + max_vote_recursive(states, days_left - states[index]['days'], index + 1) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Original Function | |
| f = (lambda x: x((lambda x: x(lambda x: x))(x)))(lambda x: x) | |
| # Reduced confusion | |
| f = ( | |
| lambda a: a( | |
| ( | |
| lambda b: b(lambda c: c) | |
| )(a) | |
| ) | 
NewerOlder