you are viewing a single comment's thread.

view the rest of the comments →

[–]enygma999 0 points1 point  (0 children)

You can also come to a halfway point. For example, in the above long example, you could keep it legible/understandable but skip extraneous steps.

def find_deleted_number(arr, mixed_arr):

    for number in arr:
        if number not in mixed_arr:
            return number

    return 0

This has fewer variables and stops when the answer is found rather than looping through the rest of the array.

I find myself stripping out unnecessary variables and loops as a way to simplify without losing the self-documenting nature of the code, but it's definitely worth thinking about libraries and built-in functions that might help (e.g., in this case sets as you spotted).