On Thu, 10 Jan 2013 09:50:37 -0800 (PST) pmec <pcura...@gmail.com> wrote:
> Hi there guys i've got a script that's suppose to find the average of two > times as strings. The times are in minutes:seconds:milliseconds > i'm doing ok in printing the right minutes and seconds my problem is with the > milliseconds. > > Example if i have 00:02:20 and 00:04:40 the average will be 00:03:30 or > 00:02:00 and 00:03:00 will be 00:02:30 This is how I would probably go about it: Convert your strings to floating point values which describe the time in seconds. Look at string.split() if you do it by hand. You could also use a regular expression ('re' module). Then, calculate the average: (a+b)*0.5 Then, convert back to your string format if you must. This may sound like more work at first but it is probably easier and less error-prone than messing with those separate values. Make sure you properly understand the string format first. minutes:seconds:milliseconds sounds unusual to me, but if you know for certain that is the format, then it is :) -- http://mail.python.org/mailman/listinfo/python-list