Created
July 16, 2013 02:54
-
-
Save ajschumacher/6005392 to your computer and use it in GitHub Desktop.
another solution to this munging problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!