@@ -434,60 +434,71 @@ def graph(self):
434434 elif n == 2 :
435435 # one edge, two vertices. We align horizontally and put
436436 # the lower number on the left vertex.
437- G .set_pos (pos = {0 :[- 0.5 ,0 ],1 : [0.5 ,0 ]})
437+ G .set_pos (pos = {0 : [- 0.5 , 0 ], 1 : [0.5 , 0 ]})
438438 else :
439439 maxdegree = max (max (N ))
440440 if n == 3 :
441441 # o--o--o
442- centervert = [ i for i in range (3 ) if max (N .row (i )) < maxdegree ][ 0 ]
442+ centervert = next ( i for i in range (3 ) if max (N .row (i )) < maxdegree )
443443 other = [i for i in range (3 ) if i != centervert ]
444- G .set_pos (pos = {centervert :[0 ,0 ],other [0 ]:[- 1 ,0 ],other [1 ]:[1 ,0 ]})
444+ G .set_pos (pos = {centervert : [0 , 0 ], other [0 ]: [- 1 , 0 ], other [1 ]: [1 , 0 ]})
445445 elif maxdegree == 4 :
446446 # o--o<8
447- centervert = [ i for i in range (4 ) if max (N .row (i )) < maxdegree ][ 0 ]
447+ centervert = next ( i for i in range (4 ) if max (N .row (i )) < maxdegree )
448448 other = [i for i in range (4 ) if i != centervert ]
449- G .set_pos (pos = {centervert :[0 ,0 ],other [0 ]:[0 ,1 ],other [1 ]:[- 0.8660254 ,- 0.5 ],other [2 ]:[0.8660254 ,- 0.5 ]})
449+ G .set_pos (pos = {centervert : [0 , 0 ], other [0 ]: [0 , 1 ],
450+ other [1 ]: [- 0.8660254 , - 0.5 ], other [2 ]: [0.8660254 , - 0.5 ]})
450451 elif maxdegree == 27 :
451452 # o--o--o--o
452453 centers = [i for i in range (4 ) if list (N .row (i )).count (3 ) == 2 ]
453- left = [j for j in range (4 ) if N [centers [0 ],j ] == 3 and j not in centers ][0 ]
454- right = [j for j in range (4 ) if N [centers [1 ],j ] == 3 and j not in centers ][0 ]
455- G .set_pos (pos = {left :[- 1.5 ,0 ],centers [0 ]:[- 0.5 ,0 ],centers [1 ]:[0.5 ,0 ],right :[1.5 ,0 ]})
454+ left = next (j for j in range (4 ) if N [centers [0 ], j ] == 3 and j not in centers )
455+ right = next (j for j in range (4 ) if N [centers [1 ], j ] == 3 and j not in centers )
456+ G .set_pos (pos = {left : [- 1.5 , 0 ], centers [0 ]: [- 0.5 , 0 ],
457+ centers [1 ]: [0.5 , 0 ], right : [1.5 , 0 ]})
456458 elif n == 4 :
457459 # square
458- opp = [i for i in range (1 ,4 ) if not N [0 ,i ].is_prime ()][0 ]
459- other = [i for i in range (1 ,4 ) if i != opp ]
460- G .set_pos (pos = {0 :[1 ,1 ],other [0 ]:[- 1 ,1 ],opp :[- 1 ,- 1 ],other [1 ]:[1 ,- 1 ]})
460+ opp = next (i for i in range (1 , 4 ) if not N [0 , i ].is_prime ())
461+ other = [i for i in range (1 , 4 ) if i != opp ]
462+ G .set_pos (pos = {0 : [1 , 1 ], other [0 ]: [- 1 , 1 ],
463+ opp : [- 1 , - 1 ], other [1 ]: [1 , - 1 ]})
461464 elif maxdegree == 8 :
462465 # 8>o--o<8
463466 centers = [i for i in range (6 ) if list (N .row (i )).count (2 ) == 3 ]
464- left = [j for j in range (6 ) if N [centers [0 ],j ] == 2 and j not in centers ]
465- right = [j for j in range (6 ) if N [centers [1 ],j ] == 2 and j not in centers ]
466- G .set_pos (pos = {centers [0 ]:[- 0.5 ,0 ],left [0 ]:[- 1 ,0.8660254 ],left [1 ]:[- 1 ,- 0.8660254 ],centers [1 ]:[0.5 ,0 ],right [0 ]:[1 ,0.8660254 ],right [1 ]:[1 ,- 0.8660254 ]})
467+ left = [j for j in range (6 ) if N [centers [0 ], j ] == 2 and j not in centers ]
468+ right = [j for j in range (6 ) if N [centers [1 ], j ] == 2 and j not in centers ]
469+ G .set_pos (pos = {centers [0 ]: [- 0.5 , 0 ], left [0 ]: [- 1 , 0.8660254 ],
470+ left [1 ]: [- 1 , - 0.8660254 ], centers [1 ]: [0.5 , 0 ],
471+ right [0 ]: [1 , 0.8660254 ], right [1 ]: [1 , - 0.8660254 ]})
467472 elif maxdegree == 18 :
468473 # two squares joined on an edge
469474 centers = [i for i in range (6 ) if list (N .row (i )).count (3 ) == 2 ]
470- top = [j for j in range (6 ) if N [centers [0 ],j ] == 3 ]
471- bl = [j for j in range (6 ) if N [top [0 ],j ] == 2 ][0 ]
472- br = [j for j in range (6 ) if N [top [1 ],j ] == 2 ][0 ]
473- G .set_pos (pos = {centers [0 ]:[0 ,0.5 ],centers [1 ]:[0 ,- 0.5 ],top [0 ]:[- 1 ,0.5 ],top [1 ]:[1 ,0.5 ],bl :[- 1 ,- 0.5 ],br :[1 ,- 0.5 ]})
475+ top = [j for j in range (6 ) if N [centers [0 ], j ] == 3 ]
476+ bl = next (j for j in range (6 ) if N [top [0 ], j ] == 2 )
477+ br = next (j for j in range (6 ) if N [top [1 ], j ] == 2 )
478+ G .set_pos (pos = {centers [0 ]: [0 , 0.5 ], centers [1 ]: [0 , - 0.5 ],
479+ top [0 ]: [- 1 , 0.5 ], top [1 ]: [1 , 0.5 ],
480+ bl : [- 1 , - 0.5 ], br : [1 , - 0.5 ]})
474481 elif maxdegree == 16 :
475482 # tree from bottom, 3 regular except for the leaves.
476483 centers = [i for i in range (8 ) if list (N .row (i )).count (2 ) == 3 ]
477- center = [ i for i in centers if len ([j for j in centers if N [i ,j ] == 2 ]) == 2 ][ 0 ]
484+ center = next ( i for i in centers if len ([j for j in centers if N [i , j ] == 2 ]) == 2 )
478485 centers .remove (center )
479- bottom = [j for j in range (8 ) if N [center ,j ] == 2 and j not in centers ][0 ]
480- left = [j for j in range (8 ) if N [centers [0 ],j ] == 2 and j != center ]
481- right = [j for j in range (8 ) if N [centers [1 ],j ] == 2 and j != center ]
482- G .set_pos (pos = {center :[0 ,0 ],bottom :[0 ,- 1 ],centers [0 ]:[- 0.8660254 ,0.5 ],centers [1 ]:[0.8660254 ,0.5 ],left [0 ]:[- 0.8660254 ,1.5 ],right [0 ]:[0.8660254 ,1.5 ],left [1 ]:[- 1.7320508 ,0 ],right [1 ]:[1.7320508 ,0 ]})
486+ bottom = next (j for j in range (8 ) if N [center , j ] == 2 and j not in centers )
487+ left = [j for j in range (8 ) if N [centers [0 ], j ] == 2 and j != center ]
488+ right = [j for j in range (8 ) if N [centers [1 ], j ] == 2 and j != center ]
489+ G .set_pos (pos = {center : [0 , 0 ], bottom : [0 , - 1 ], centers [0 ]: [- 0.8660254 , 0.5 ],
490+ centers [1 ]: [0.8660254 , 0.5 ], left [0 ]: [- 0.8660254 , 1.5 ],
491+ right [0 ]: [0.8660254 , 1.5 ], left [1 ]: [- 1.7320508 , 0 ], right [1 ]: [1.7320508 , 0 ]})
483492 elif maxdegree == 12 :
484493 # tent
485494 centers = [i for i in range (8 ) if list (N .row (i )).count (2 ) == 3 ]
486- left = [j for j in range (8 ) if N [centers [0 ],j ] == 2 ]
495+ left = [j for j in range (8 ) if N [centers [0 ], j ] == 2 ]
487496 right = []
488497 for i in range (3 ):
489- right .append ([j for j in range (8 ) if N [centers [1 ],j ] == 2 and N [left [i ],j ] == 3 ][0 ])
490- G .set_pos (pos = {centers [0 ]:[- 0.75 ,0 ],centers [1 ]:[0.75 ,0 ],left [0 ]:[- 0.75 ,1 ],right [0 ]:[0.75 ,1 ],left [1 ]:[- 1.25 ,- 0.75 ],right [1 ]:[0.25 ,- 0.75 ],left [2 ]:[- 0.25 ,- 0.25 ],right [2 ]:[1.25 ,- 0.25 ]})
498+ right .append (next (j for j in range (8 ) if N [centers [1 ], j ] == 2 and N [left [i ], j ] == 3 ))
499+ G .set_pos (pos = {centers [0 ]: [- 0.75 , 0 ], centers [1 ]: [0.75 , 0 ], left [0 ]: [- 0.75 , 1 ],
500+ right [0 ]: [0.75 , 1 ], left [1 ]: [- 1.25 , - 0.75 ], right [1 ]: [0.25 , - 0.75 ],
501+ left [2 ]: [- 0.25 , - 0.25 ], right [2 ]: [1.25 , - 0.25 ]})
491502 G .set_vertices (D )
492503 G .relabel (list (range (1 , n + 1 )))
493504 return G
0 commit comments