You can append all the values at the second place (number b) in a list for a particular group (say, 789). Then just iterate over the list using nested loops and you can get all the moves you want. Hope this is what you want.
Code:
for i in range(1,118):
for j in range(1,118):
count=0
for p in range(len(list)-1):
if(list[p]==i and list[p+1]==j):
count+=1
if(count!=0):
#print/write Statement here
If you’re still stuck I can help you 🙂
10
solved Python : count the number of changes of numbers