Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created November 1, 2012 21:18
Show Gist options
  • Select an option

  • Save daGrevis/3996622 to your computer and use it in GitHub Desktop.

Select an option

Save daGrevis/3996622 to your computer and use it in GitHub Desktop.
Calculates depth of comments w/ recursion.
@staticmethod
def calculate_depth(comments, comment=None, depth_level=1):
"""
@brief Calculates depth of comments w/ recursion.
@param comments: Comments
@param comment: Comment (for recursion, isn't used from outside)
@param depth_level: Depth level (for recursion, isn't used from outside)
@return Comments /w depth level
"""
for the_comment in comments:
if the_comment.parent == comment:
the_comment.depth_level = depth_level
Comment.calculate_depth(comments, the_comment, depth_level + 1)
return comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment