If your function accepts input line by line, you may use function-level caching. I will show you how to use
Let's start by splitting the line unconditionally
mutable default value
to this end Let's start by splitting the line unconditionally
def parse_mochad_line(self, line, _house_unit=[]): elements = line.split() classifier = ''.join(elements[2:4]) if classifier == 'RxRFSEC': ...... elif classifier == 'RxRF': ..... elif classifier == 'RxPL': if not house_unit: _house_unit.append(...) else: ...... _house_unit.clear()Pay attention - you cannot assign
_house_unit
, because that will ruin caching mechanism
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.