Skip to content

DOC: Add docstring example count number of unique triangles - #8144

Merged
dschult merged 2 commits into
networkx:mainfrom
rossbar:doc-num-unique-triangles
Jul 13, 2025
Merged

dschult merged 2 commits into
networkx:mainfrom
rossbar:doc-num-unique-triangles

Conversation

@rossbar

@rossbar rossbar commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

A simple solution to the problem originally posed in #8135 - so simple (and nice in the sense that it uses triangles instead of other alternatives like cycles or triads) that I thought it was worth documenting! Thanks @dschult for pointing it out!

One (simple) way of counting the total number of unique triangles
in G.

Co-authored-by: Dan Schult <[email protected]>

@Peiffap Peiffap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a neat example indeed! LGTM.

Maybe something like "The total number of unique triangles in G can be determined by summing the number of triangles for each node and dividing by 3 (because a given triangle gets counted three times, once for each of its nodes)." would be slightly more explicit?

@rossbar

rossbar commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

Maybe something like

I'm happy with whatever wording - if you make the suggestion I will commit it!

Comment thread networkx/algorithms/cluster.py Resolved

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rossbar and @Peiffap

@dschult
dschult merged commit 4410959 into networkx:main Jul 13, 2025
amcandio pushed a commit to amcandio/networkx that referenced this pull request Jul 20, 2025
…#8144)

* Add docstring example to triangles

One (simple) way of counting the total number of unique triangles
in G.

Co-authored-by: Dan Schult <[email protected]>

* Update networkx/algorithms/cluster.py

Co-authored-by: Gilles Peiffer <[email protected]>

---------

Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Gilles Peiffer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants