I need to make a dictionary list like this (match the owner with their pet type) from log.txt
dictionary = {
"Sophia": "Cat",
"Julia": "Bird",
"Max": "Dog"
}
log.txt
Pet Owner : Sophia
Colour : Blue
Pet Type : Cat
From : India
Price : High
Pet Owner : Bruce
Not own pet
Pet Owner : Sean
Not own pet
Pet Owner : Julia
Colour : Yellow
Pet Type : Bird
From : Israel
Price : Low
Pet Owner : Bean
Not own pet
Pet Owner : Max
Colour : Green
Pet Type : Dog
From : Italy
Price : Normal
Pet Owner : Clarie
Not own pet
What I have try so far
import re
log = open("log.txt", "r")
txt = log.read()
log.close()
x = re.search("^Pet.Owner.+", txt)
print(x.group())
I stuck at here, I don't know how to make the regEx return 2 keyword that I wanted and save it to the dictionary.txt.