Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Python script to parse the provided file animals.txt. Use Regular Expressions, import re Parse each line of the file. If the line starts
Write a Python script to parse the provided file animals.txt.
Use Regular Expressions, import re
Parse each line of the file.
If the line starts with # ignore it.
If the line has this organization: has .
1. Add the number to the dictionary perperson[name].
2. Add the number to the dictionary animaltypecount[animaltype]
After Parsing the file print the following:
1.Print the names of all people with pets. Avoid printing duplicates.
Ex. Jesse has 2 pet(s).
2.Print the number of pets per animal type.
Ex. There are 3 dog(s).
animals.txt this is a comment - ignore me George has 5 giraffe Ryan has 3 snake. Lisa has 7 cat. Melonie has 12 horse. #Tristan has 1 dog Tommy has 1 dog Tammy has 4 elephant. SueAnne has 5 cat. Aaron has 3 dog Sharon has 2 cat. Ralph has 1 snake. Tim has 2 dog #This is the last line. animals.txt this is a comment - ignore me George has 5 giraffe Ryan has 3 snake. Lisa has 7 cat. Melonie has 12 horse. #Tristan has 1 dog Tommy has 1 dog Tammy has 4 elephant. SueAnne has 5 cat. Aaron has 3 dog Sharon has 2 cat. Ralph has 1 snake. Tim has 2 dog #This is the last lineStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started