On 7 May 2013 21:10, Linsey Raaijmakers <lm.raaijmak...@gmail.com> wrote: > Hi, > > Im trying to work with the help Oscar provided me, but I still get stuck :(
For the benefit of everyone else here, this is referring to a question that was asked on python-list. The discussion there went off-list and I recommended that it take place on-list but on this list instead of python-list. > So what I'm trying to do now is write the program with the following input > and output: The input/output specification below was my own suggestion of a subproblem to solve. The idea is that actions with integer identifiers have integer start/apex/end times and the program should read a file containing those and identify when actions are occurring simultaneously. The events in the file appear in order of start time. > Input: > action,start,apex,stop > 3, 12, 13, 15 > 4, 15, 15, 15 > 3, 20, 21, 25 > 5, 21, 23, 30 > ... > > And when you run your program it prints out: > actions, start, stop > [3], 12, 13 > [], 14,15 > [4], 15, 15 > [], 16, 19 > [3], 20, 21 > [3, 5], 21, 21 > [5], 22, 23 > ... > > I don't want to use the stop. Only the start till apex is important. > > This is the code I have now: Not it's not. This code doesn't work. Can you post a complete program that actually runs rather than just a segment of it? See here: http://sscce.org/ > > now = onset_list[0] > end = apex_list[0] > active = action_list[0] > > for i in range(1,len(onset_list)): > next_start = onset_list[i] > next_end = apex_list[i] > next_active = action_list[i] > prev_end = apex_list[i-1] > > while next_start > end: > print active+"\t"+now+'\t'+end > end = next_end > now = next_start > active = next_active > print active+','+next_active+'\t'+now+'\t'+next_end This will just print each event and the following event. That is not what you want. You need to keep a list of currently active events and as you loop forward through the times you should remove events that have finished and add events that have started. > But my output will print now: > > 3 12 13 > 4,4 15 15 > 4 15 15 > 3,3 20 21 > 3,5 20 25 > > How do I fix that it doesn't print out the double ones? The problem is not that it prints the double ones. The problem is that it does not keep track of a list of currently active events. I'll make the problem a bit simpler: make a program that gives the following input/output. Input: action,start,apex,stop 3, 12, 13, 15 4, 15, 15, 15 3, 20, 21, 25 5, 21, 23, 30 ... And when you run your program it prints out: actions, time [3], 12 [3], 13 [], 14 [4], 15 [], 16 [], 17 [], 18 [], 19 [3], 20 [3, 5], 21 [5], 22 [5], 23 ... The first column in this output is the list of active events at the times given in the second column. Your code will need to actually have a list that it adds and removes from as events start and stop Oscar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor