Skip to content

Instantly share code, notes, and snippets.

@ajschumacher
Created July 16, 2013 02:54
Show Gist options
  • Save ajschumacher/6005392 to your computer and use it in GitHub Desktop.
Save ajschumacher/6005392 to your computer and use it in GitHub Desktop.
another solution to this munging problem
movie_reviews = dict()
for line in open('movies.txt.small'):
pieces = line.split(':')
if len(pieces) > 1:
key = pieces[0]
value = ':'.join(pieces[1:]).strip()
if key == 'product/productId':
id = value
if key == 'review/text':
movie_reviews.setdefault(id, []).append(value)
for movie, reviews in movie_reviews.items():
print movie, reviews
@ajschumacher
Copy link
Author

Using 'id' as a variable name is not actually such a good idea, since it's the name of a built-in function, but it works okay here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment