The following code works just fine. But it seems so verbose, surely there is a more elegant way to calculate this?
The idea is that I have a list of 100 incrementing timestamps, I want to look at those timestamps and calculate the mean time between each time-stamp.
The code below functions, but I’m sure it’s really inefficient to be reversing lists like this.
Any suggestions?
#!/usr/bin/python
nums = [1,4,6,10]
print nums
nums_orig = list(nums)
nums_orig.pop()
nums.reverse()
nums.pop()
nums.reverse()
print nums
print nums_orig
total = 0
for idx, val in enumerate(nums):
difference = val - nums_orig[idx]
total += difference
print idx, val - nums_orig[idx]
print "Mean difference is %d" % (total / len(nums))
What you are looking for is
Solution with using Starmap