C.<p><span class="h-card"><a href="https://meow.social/@FluffyDeveloper" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>FluffyDeveloper</span></a></span> </p><p>I suspect there's something else going on here, or your comments data is far different than I'm supposing.</p><p>Your flatten method works just fine for me with a tree of 600 comments. In fact, it works fine with 600,000 comments (recurs. lim. 1000)</p><p>Example test script:<br><a href="https://pastebin.com/6Mdvu2WL" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="">pastebin.com/6Mdvu2WL</span><span class="invisible"></span></a></p><p>Without seeing your other code, I don't know what the issue you're running into. At a wild guess, is it possible your graph is not acyclic?</p><p><a href="https://mindly.social/tags/recursion" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>recursion</span></a> <a href="https://mindly.social/tags/python" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>python</span></a> <a href="https://mindly.social/tags/graph" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>graph</span></a> <a href="https://mindly.social/tags/cyclic" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>cyclic</span></a> <a href="https://mindly.social/tags/acyclic" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>acyclic</span></a></p>