Im relatively new to python and I have a file containing words/lines like this:
AA EY2 EY1
AAA T R IH2 P AH0 L EY1
AABERG AA1 B ER0 G
AACHEN AA1 K AH0 N
AACHENER AA1 K AH0 N ER0
AAH AA1
AAKER AA1 K ER0
AALIYAH AA2 L IY1 AA2
AALSETH AA1 L S EH0 TH
AAMODT AA1 M AH0 T
AANCOR AA1 N K AO2 R
what i need to do read these into a dictionary with the key being the first word/entry of each line, and that is mapped to a list containing each string. for example- AA: "EY2", "EY1"
that way i can search for two words (indexes of the dictionary) and compare their lists. I've got a basic loop to read the file line by line stripping the newline character but not sure how to precede.
AA EY2 EY1
AAA T R IH2 P AH0 L EY1
AABERG AA1 B ER0 G
AACHEN AA1 K AH0 N
AACHENER AA1 K AH0 N ER0
AAH AA1
AAKER AA1 K ER0
AALIYAH AA2 L IY1 AA2
AALSETH AA1 L S EH0 TH
AAMODT AA1 M AH0 T
AANCOR AA1 N K AO2 R
what i need to do read these into a dictionary with the key being the first word/entry of each line, and that is mapped to a list containing each string. for example- AA: "EY2", "EY1"
that way i can search for two words (indexes of the dictionary) and compare their lists. I've got a basic loop to read the file line by line stripping the newline character but not sure how to precede.
d= {} with open(fName) as f: while True: line = f.readline() if not line.startswith(";;;"): break for line in f: print(line, end="")i feel its important to recognize that after each of the first words in every line theres a double space. not just a single space. which has me a little tripped up since my first instinct was to use .split