On Tue, 11 Jan 2005, kevin parks wrote:

> but as always you may notice a wrinkle.... some items have many times
> (here 6) indicated:
>
> Item_3    TAPE_1    3    9:41    10:41
> Item_3    TAPE_1    4    10:47    11:19
> Item_3    TAPE_1    5    11:21    11:55
> Item_3    TAPE_1    6    11:58    12:10
> Item_3    TAPE_1    7    12:15    12:45    Defect in analog tape sound.
> Item_3    TAPE_1    8    12:58    24:20    Defect in analog tape sound.


Hi Kevin,

It may help make things more managable if you work on a smaller
subproblem.


Let's look at the time-joining problem and see if that's really as hard as
it looks.  Let's just select the time coordinates and concentrate on those
for now.

######
9:41    10:41
10:47    11:19
11:21    11:55
11:58    12:10
12:15    12:45
12:58    24:20
######


I notice here that this representation is in minutes and seconds.  It
might be easier if we make the data all in seconds: we can do our numeric
calculations much more easily if we're dealing with a single unit.

###
def convertMinSecToSeconds(minSecString):
    """Converts a string of the form:

       min:sec

       into the integer number of seconds.
    """
    min, sec = minSecString.split(":")
    return (int(min) * 60) + int(sec)
###


If we need to go back from seconds back to the minute-second
representation, we can write a function to go the other direction.


Anyway, with that, we can now look at the problem purely in seconds:

###
>>> times = """
... 9:41    10:41
... 10:47    11:19
... 11:21    11:55
... 11:58    12:10
... 12:15    12:45
... 12:58    24:20
... """.split()
>>>
>>> times
['9:41', '10:41', '10:47', '11:19', '11:21', '11:55', '11:58', '12:10',
'12:15', '12:45', '12:58', '24:20']
>>>
>>> seconds = map(convertMinSecToSeconds, times)
>>> seconds
[581, 641, 647, 679, 681, 715, 718, 730, 735, 765, 778, 1460]
###




That is, we now have some input, like:

######
initialInput = [(581, 641),
                (647, 679),
                (681, 715),
                (718, 730),
                (735, 765),
                (778, 1460)]
######


And now we want to turn it into something like:

###
expectedResult = [(0, 60),
                  (60, 98),
                  (98, 134),
                  (134, 149),
                  (149, 184),
                  (184, 879)]
###

Can you write a function that takes this 'initialInput' and produces that
'expectedResult'?  If so, your problem's pretty much solved.



If you have more questions, please feel free to ask.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to