Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

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 line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

Students also viewed these Databases questions

Question

Has the priority order been provided by someone else?

Answered: 1 week ago