i have to implement a stable marriage problem in python where 'n' men and 'n' women will have a preference list each and the algorithm matches them according to it. i have to input the number of participants 'n' and both male and female preferences in a single text file.
right now im inputting using two files and the algorithm works fine but i need to keep all the data in a single file.
my code is
import copy
f = open('C:\\Users\\Rakshith\\Desktop\\ADA project\\uyt.txt','r')
malepreferences = eval(f.read())
print(malepreferences)
g = open('C:\\Users\\Rakshith\\Desktop\\ADA project\\uuu.txt','r')
femalepreferences=eval(g.read())
print(femalepreferences)
one of my two input files look like
{
'john': ['jennifer', 'alexis', 'abby', 'megan', 'kate', 'anna', 'samantha', 'ashley', 'emma', 'jesse'],
'harvey': ['abby', 'emma', 'jennifer', 'anna', 'alexis', 'samantha', 'ashley', 'kate', 'megan', 'jesse'],
'kumar': ['emma', 'alexis', 'jennifer', 'anna', 'ashley', 'samantha', 'megan', 'jesse', 'abby', 'kate'],
'David': ['megan', 'samantha', 'anna', 'jesse', 'emma', 'alexis', 'kate', 'ashley', 'abby', 'jennifer'],
'jim': ['kate', 'anna', 'ashley', 'abby', 'samantha', 'alexis', 'jennifer', 'megan', 'emma', 'jesse'],
'fred': ['ashley', 'jennifer', 'anna', 'jesse', 'alexis', 'megan', 'abby', 'kate', 'emma', 'samantha'],
'peter': ['jesse', 'alexis', 'megan', 'ashley', 'abby', 'jennifer', 'anna', 'emma', 'kate', 'samantha'],
'patel': ['jennifer', 'alexis', 'emma', 'samantha', 'megan', 'abby', 'kate', 'ashley', 'jesse', 'anna'],
'mike': ['emma', 'abby', 'anna', 'jesse', 'ashley', 'jennifer', 'samantha', 'megan', 'kate', 'alexis'],
'randy': ['jennifer', 'samantha', 'kate', 'jesse', 'alexis', 'ashley', 'anna', 'abby', 'megan', 'emma']}
my input file should look like this
n
m1: w11, w12, ..., w1n
mn: wn1, wn2, ..., wnn
...
...
...
w1: m11, m12, ..., m1n
wn: mn1, mn2, ..., mnn