daffidwilde / matching

A package for solving matching games
https://daffidwilde.github.io/matching/
MIT License
149 stars 42 forks source link

How to transform SingleMatching class into a Python Dictionary? #140

Closed eltxejo closed 1 year ago

eltxejo commented 1 year ago

Hi there,

Once the Stable Marriage game is solved, I would like to retrieve the solution data into a Python dictionary in order to manipulate the data for further actions.

How could I do it?

Thanks

daffidwilde commented 1 year ago

Hi there, @eltxejo. Apologies that it has been some time since you opened this issue.

The SingleMatching class is effectively a dictionary already. However, if you would like to create one and export the players using their names, this should do the trick:

from matching.games import StableMarriage

game = StableMarriage(players)
matching = game.solve()

matching_dict = {player.name: match.name for player, match in matching.items()}

It may be worth me adding a how-to with this to the documentation!

eltxejo commented 12 months ago

That made it!

Thank you, @daffidwilde