I just came across this question. All the solutions given are in PERL for this question. I thought I can learn solving this in Python as I could learn many thing by solving this problem. But I am stuck. The question is:
You are working at a grocery store which tracks its customers' purchasing habits
by scanning frequent shoppers' cards. Your cash registers logs all transactions
to a pipe-delimited ("|") flat text file in the following format:
customer_name|product_category|item_description|cost
An example log file could be:
Pedro|groceries|apple|1.42
Nitin|tobacco|cigarettes|15.00
Susie|groceries|cereal|5.50
Susie|groceries|milk|4.75
Susie|tobacco|cigarettes|15.00
Susie|fuel|gasoline|44.90
Pedro|fuel|propane|9.60
Write a script/program (in your language of choice) that will parse the log and
generate the following output:
A report of the total revenue resulting from each customer.
A report for each customer showing how much of their spending went to each category.
With the above example log file, the script should output should be something like:
Total Revenue:
Pedro - $11.02
Nitin - $15.00
Susie - $70.15
Purchases by Pedro:
groceries - $1.42
fuel - $9.60
Purchases by Nitin:
tobacco - $15.00
Purchases by Susie:
groceries - $10.25
fuel - $44.90
tobacco - $15.00
quare have?:
I just worte a piece of code to read the "|" delimeted file. but I don't know how to procedd further like how to group them in category and solve this problem. Can anyone explain me the idea of how to solve this.`Inline Code Example Here
def filefunc():
file_input = raw_input("Enter the name of the file: ")
file_open = open(file_input, "r")
file_read = file_open.readline()
i = 1
while file_read:
print file_read,
file_read = file_open.readline()
i = i + 1
# print file_read
file_open.close()
filefunc()
`