Python Forum
processes a series of text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
processes a series of text file
#1
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!
Reply
#2
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)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert text from an image to a text file Evil_Patrick 5 4,300 Jul-30-2019, 07:57 PM
Last Post: DeaD_EyE
  reading text file and writing to an output file precedded by line numbers kannan 7 10,413 Dec-11-2018, 02:19 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020