def assign_comments(self, tree, comments):
comments = list(comments)<EOL>comments.sort(key=lambda c: c.line)<EOL>idx_by_line = {<NUM_LIT:0>: <NUM_LIT:0>}  <EOL>for i, c in enumerate(comments):<EOL><INDENT>if c.line not in idx_by_line:<EOL><INDENT>idx_by_line[c.line] = i<EOL><DEDENT><DEDENT>idx = []<EOL>self.comments = [c.value.strip() for c in comments]<EOL>last_comment_line = max(idx_by_line.keys())<EOL>for i in range(last_comment_line, <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>if i in idx_by_line:<EOL><INDENT>idx.append(idx_by_line[i])<EOL><DEDENT>else:<EOL><INDENT>idx.append(idx[-<NUM_LIT:1>])<EOL><DEDENT><DEDENT>idx.append(<NUM_LIT:0>)  <EOL>idx.reverse()<EOL>self.idx = idx<EOL>self._assign_comments(tree, <NUM_LIT:0>)<EOL>
Capture any comments in the tree

header_comments stores comments preceding a node