[datetime.datetime(2021, 12, 20, 16, 54, 56), datetime.datetime(2021, 12, 20, 16, 54, 57), datetime.datetime(2021, 12, 20, 16, 54, 57)]
from more_itertools import windowed
import datetime
import statistics
dates = [
datetime.datetime(year=2021, month=12, day=20, hour=16, minute=54, second=56),
datetime.datetime(year=2021, month=12, day=20, hour=16, minute=54, second=57),
datetime.datetime(year=2021, month=12, day=20, hour=16, minute=54, second=57),
]
diffs = []
for first, second in windowed(dates, 2):
diffs.append((second-first).total_seconds())
print(f'Avg: {statistics.mean(diffs)}')
Avg: 0.5
Process finished with exit code 0