Exercise

# Identifying triangle relationships

Now that you've learned about cliques, it's time to try leveraging what you know to find structures in a network. Triangles are what you'll go for first. We may be interested in triangles because they're the simplest complex clique. Let's write a few functions; these exercises will bring you through the fundamental logic behind network algorithms.

In the Twitter network, each node has an `'occupation'`

label associated with it, in which the Twitter user's work occupation is divided into `celebrity`

, `politician`

and `scientist`

. One potential application of triangle-finding algorithms is to find out whether users that have similar occupations are more likely to be in a clique with one another.

Instructions

**100 XP**

- Import
`combinations`

from`itertools`

. - Write a function
`is_in_triangle()`

that has two parameters -`G`

and`n`

- and checks whether a given node is in a triangle relationship or not.`combinations(iterable, n)`

returns combinations of size`n`

from`iterable`

. This will be useful here, as you want combinations of size`2`

from`G.neighbors(n)`

.- To check whether an edge exists between two nodes, use the
`.has_edge(node1, node2)`

method. If an edge exists, then the given node is in a triangle relationship, and you should return`True`

.