Python Forum

Full Version: processes a series of text file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone! I should solve an exercise in python language and I am not able. This is the exercise:
"Create a Python program that processes a series of text files that contain information related to a set of recipes.
File: Apple Pie.txt
Apples, 4
Sugar, 5
Flour, 6
Eggs, 2

File: Spaghetti in white.txt
Spaghetti, 100

Each file is called as a recipe. It contains the ingredients of that recipe. Each ingredient also has a quantity.

1. For each ingredient, print how many recipes it is associated with.
2. Find recipes that share at least 2 ingredients.
3. For each recipe print how many are its ingredients.
4. Find recipes with the same ingredients.

Thanks in advance!
What have you tried and where did you get stuck?

Some ideas:

It's unclear whether you have list of filenames on you should scan a directory. You should address that and process all required files.

For every file program must do:

# read the file:
# store data from file (with association between recipe, ingredient, qty)

Then you have to query stored data to get answers for 4 questions asked.

After identifying general tasks you can proceed with smaller steps:

- how to read file
- how to process data in file
- how to store processed data (which datastructure, which datatype etc)