3 ms·
For me that's the issue with this whole example; it kinda misses the woods for the trees. # not interesting (also, use stdlib instead) def extract_url_
by aidos 4y ago
For me that's the issue with this whole example; it kinda misses the woods for the trees.
# not interesting (also, use stdlib instead)
def extract_url_params(url: str) -> dict[str, str]:
params = url.split('?')[1].split('&')
return = dict(param.split('=') for param in params)
# This is the thing that needs explaining!
final_3_param_values = list(extract_url_params(url).values())[-3:]
By decomposing the problem in a more natural way, you can entirely direct the reader's attention to the thing that's causing the dissonance. For some reason it's just the the final 3 values they want (both weird requirements). Make that clear from the code!
- philipwhiuk 4y ago> For some reason it's just the the final 3 values they want (both weird requirements). Make that clear from the code! Yeh, I mean the name should really tell you what those expected to be. `hopefully_auth_param_values` is almost a better name