Large amount of files to parse/organize, tips on algorithm?

C

cnb

I have a bunch of files consisting of moviereviews.

For each file I construct a list of reviews and then for each new file
I merge the reviews so that in the end have a list of reviewers and
for each reviewer all their reviews.

What is the fastest way to do this?

1. Create one file with reviews, open next file an for each review see
if the reviewer exists, then add the review else create new reviewer.

2. create all the separate files with reviews then mergesort them?
 
S

Steven D'Aprano

I have a bunch of files consisting of moviereviews.

For each file I construct a list of reviews and then for each new file I
merge the reviews so that in the end have a list of reviewers and for
each reviewer all their reviews.

What is the fastest way to do this?

Use the timeit module to find out.

1. Create one file with reviews, open next file an for each review see
if the reviewer exists, then add the review else create new reviewer.

2. create all the separate files with reviews then mergesort them?

The answer will depend on whether you have three reviews or three
million, whether each review is twenty words or twenty thousand words,
and whether you have to do the merging once only or over and over again.
 
C

cnb

Use the timeit module to find out.



The answer will depend on whether you have three reviews or three
million, whether each review is twenty words or twenty thousand words,
and whether you have to do the merging once only or over and over again.



I merge once. each review has 3 fields, date rating customerid. in
total ill be parsing between 10K and 100K, eventually 450K reviews.
 
P

Paul Rubin

cnb said:
For each file I construct a list of reviews and then for each new file
I merge the reviews so that in the end have a list of reviewers and
for each reviewer all their reviews.

What is the fastest way to do this?

Scan through all the files sequentially, emitting records like

(movie, reviewer, review)

Then use an external sort utility to sort/merge that output file
on each of the 3 columns. Beats writing code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top