« first day  last day (15 days later) » 

2:44 PM
In a comment you have object1.id = object5.pred, how are the two attribute related, what exactly are you checking against?
I think a small example of input and your expected output would be helpful
 
 
2 hours later…
5:07 PM
i'm writing a program that finds the critical path of a set of activities, i'm trying to get all the possible path in the network .so pred stands for predecessors of an activity and id is an identifier(i.e) name of the activity
so i'm trying to check if the predecessor of any activity in List2 is equal to the id of any activity in List1, if there are equal then i want to append that activity to the source where it was found that is the reason why i have nested list so at the end of the day i can just print out the id's of activities in the nested list take a look at this link hspm.sph.sc.edu/Courses/J716/CPM/CPM.html
obviously this my supposed method of finding all the paths in the network will fail when there are numerous activities with the same predecessors
 
 
2 hours later…
6:52 PM
so the id and pred are the only things you care about?
 
yes
 
Ok create a minimal example using actual object and what output you want.
 
lets say A,B, C, D are the objects = criticalPath(), and their predecessors are None,None, A, B respectively if the starting activities on node 1 will be A and B since they have no predecessors, this was how i got List1 in my code
 
can you add it to your question and actually instantiate the objects.
 
should i instantiate them manually like A = criticalPath instead of using user input
 
7:07 PM
yes, that will be fine, I just want to see exactly how they are created.
 
ok
 
7:33 PM
i'm done with that i want to paste on pastebin.com so i won't mess up the original question should i?
 
sure whatever suitd
suits*
 
so that relates to List2?
What about List1?
 
ok let me generate that now
 
8:09 PM
what is your expected output?
 
[[A,C],[B,D]]
 
Ok try this, this is a Bruteforce way of doing it pastebin.com/DYaaFZF6, do you want the objects or the id appended?
 
yes i want the objects appended and your code works!!
now it's remains for me to apply this same logic to the main program
 
8:29 PM
I will add a second way to do it with a dict which is a linear solution. If you have a large amount of nodes it will be more efficient
I edited my answer with both solutions
 
8:46 PM
ok, i think i'll stick with the first option because i'll still need to do so more logic and calculations before appending (remember me saying my approach won't work if the there are numerous activities with the same predecessor ) and performance/efficiency is not really an issue now...Thanks for all your help
 
No worries, you're welcome. It is plenty fast enough for small input, I just added a more efficient way , anyone who comes across the question with a similar problem also may find it useful.
 
9:07 PM
also i modified the code a little bit i changed the == to in here: if st_nodes[0].id in node.pred: because node.pred is supposed to be a tuple not a string i made a mistake when trying to convert the string to a tuple
 
9:18 PM
so you could edit your answer for any one who comes across the question
 

« first day  last day (15 days later) »