In here it may be clearer to use a normal for loop instead of a list comprehension that is more explicit about the operations (better readability, easier to make changes). See my note about the structure of format_result.