How to obtain positions of graphs satisfying certain conditions?

I first generate some random graphs, and then the following code can filter graphs with maximum degree 8.

glist= Table[RandomGraph[{10, 25}], {i, 1, 10}];
Select[glist, Max@VertexDegree[#] == 8 &]


But now I want to see the positions of the filtering graphs in glist. It seems 'Position' is ok, but I lost in many times.

Position[glist, Max@VertexDegree[#] == 8 &] (*always nothing*)

Position[glist, x_ /; Max@VertexDegree@x == 8]


The second did produce results, but it also gave an error warning.

• Position[glist, _?(Max@VertexDegree@# == 8 &)] . You are almost there.
– Syed
Commented Jan 16 at 9:51
• The second form should be: Position[glist, x_Graph /; Max@VertexDegree@x == 8]. It is because it is expecting a Graph object and x is a general pattern object.
– Syed
Commented Jan 16 at 10:11
• Nice. You can write an answer. Commented Jan 16 at 10:24

The first form requires PatternTest as Position requires a pattern for matching.

As opposed to this the Select command requires a function that operates on elements to return a True or False value.

Parentheses are important.

Position[glist, _Graph?(Max@VertexDegree@# == 8 &)]


The second attemp using Condition requires a Graph object for which the VertexDegree function can be executed without warning. The correct form is:

Position[glist, x_Graph /; Max@VertexDegree@x == 8]


Result:

Depending on SeedRandom[], the positions of Graph objects matching the stated criteria about the VertexDegree will be returned. E.g.,

{{5}, {9}}

• Your first one also shows a warning on my computer (Mathematica 13.3). Position[glist, _Graph?(Max@VertexDegree@# == 8 &)] is well. Commented Jan 16 at 11:15
• Thanks for the accept and the heads up. I have updated the answer.
– Syed
Commented Jan 16 at 11:22