Minimum Absolute Difference in an Array

  • + 1 comment

    In this case, if the "list by comprehension" to which you refer is presumably that which is inside the min function, then your assertion is false.

    Here in Python3, a generator is being passed to the min function, so no list is being created in memory for it. Elements are being discovered through lazy evaluation of the formula. The minimum is a greedy operation running over the indices i, so it does not store the previous values a[i+1]-a[i] as it proceeds forward. It just finds the minimum up to that point when the i-th term is considered.