There is an error earlier in the program that I am attempting to find, but was asked to explain what is happening in this part of the code. Below is the code and what I think it is doing, but am unclear on some certain points. Some help in understanding would be greatly appreciated.
for title in titles:
secString = 'sec_%02d' % (title)
titleCitations = [c for c in cEdges if secString in c[0]]
intraCitations = [c for c in titleCitations if secString in c[1]]
print title, len(titleCitations), len(intraCitations), len(titleCitations) - len(intraCitations)
First, secString takes the remainder of 'sec_%02d' with respect to title, (I think this is just finding all strings that have a reference to a title?). It then creates a list titlecitations.
Though I am confused by the bracketed part. If I understand correctly, it takes the cEdge which I believe is just a list of a pairing of numbers from a given US legal code reference i.e. 26 USC 501 becomes just (26, 501), and asks if secString has a value in the c[0] spot.
(This is where I get confused; I am guessing that the c[0] spot maybe corresponds to the 26 in the above example and c[1] would correspond to the 501? Of course I am not even sure if I am understanding the c part correctly.)
Then put it in titlecitations if the c[0] spot is filled. It then creates the intracitations list. This list looks at the titlecitations list and asks if in secString is the c[1] filled and if so put it in this list.
I know there is a problem with something because titlecitations and intracitations appear to be the same list then.
The
%operator on a string isn’t modulus, it’s a formatting operator that behaves like C’s printf().%02dis a formatting code that formatstitleas a two-digit number. Iftitleis only one digit then it pads it with a0(e.g. 9 becomes09).That is correct.
This searches through the items in
cEdgesand finds ones where the title contains the stringsec_XYwhere XY is that two-digit number from earlier.Now it searches through the things we found in the previous step, again searching for the sub-string
sec_XY.The end result is that
intraCitationscontains a list of all the items fromcEdgeswhere both the first and second item contain the substringsec_XY.