0

With the duration values given as a list of strings:

durations = ['00:00:59:35','00:00:55:18', '00:01:04:28']

I need to get the integer values representing the seconds.

Attempt to do it with:

from dateutil.parser import parse
result = parse('00:00:59:35')

Getting a traceback: ValueError: Unknown string format.

Is there a way to convert this string format to the seconds?

kmario23
  • 50,454
  • 13
  • 141
  • 141
alphanumeric
  • 15,954
  • 55
  • 201
  • 355

1 Answers1

1

I'm assuming the format is as @tdelaney said. And if you want the seconds then you can use this list comprehension.

durations = ['00:00:59:35','00:00:55:18', '00:01:04:28']
secs = [int(d.split(":")[2]) for d in durations]
kmario23
  • 50,454
  • 13
  • 141
  • 141