Skip to content

Instantly share code, notes, and snippets.

@nickserv
Last active December 20, 2016 20:43
Show Gist options
  • Save nickserv/e12b49d2eb937d462ec231d3b8467fa3 to your computer and use it in GitHub Desktop.
Save nickserv/e12b49d2eb937d462ec231d3b8467fa3 to your computer and use it in GitHub Desktop.
Simple Python 3 script to sum a list of durations. Data from https://soundcloud.com/wmstrecs/sets/n-o-i-s-e.
4:24
1:58
4:47
3:44
3:55
1:53
6:49
4:04
12:01
3:24
5:10
4:03
16:55
7:38
3:37
18:44
from datetime import timedelta
from functools import reduce
from operator import add
def parse_duration(duration_string):
sections = map(int, duration_string.split(':'))
return timedelta(minutes=next(sections), seconds=next(sections))
with open("durations.txt") as f:
duration_strings = f.readlines()
print(reduce(add, map(parse_duration, duration_strings)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment