A Pythonic way to do MapReduce using hadoop
dynamicguy.com
A Pythonic way to do MapReduce using hadoop
1–4 of 4 posts
Re: A Pythonic way to do MapReduce using hadoop
#2Just wondering, is it better performance-wise to explicitly check for key membership than to rely on exceptions?
Existing:
for line in sys.stdin:
name, marks = line.rstrip().split('\t')
try:
if agregatedmarks.get(name):
agregatedmarks.get(name).append(marks)
else:
agregatedmarks[name] = [marks]
except ValueError:
pass
Or for line in sys.stdin:
name, marks = line.rstrip().split('\t')
if name in aggregatedmarks:
aggregatedmarks.append(marks)
else:
aggregatedmarks[name] = [marks]
This is a common idiom I find myself using (append to an existing list or creating a new one in a larger dict).Re: A Pythonic way to do MapReduce using hadoop
#3Great overview, from top to bottom. Just wondering, is it better performance-wise to explicitly check for key membership than to rely on exceptions? Existing: for line in sys.stdin: name, marks = line.rstrip().split('\t') try: if agregatedmarks.get(name): agregatedmarks.get(name).append(marks) else: agregatedmarks[name] = [marks] except ValueError: pass Or for line in sys.stdin: name, marks = line.rstrip().split('\t'…
See http://docs.python.org/release/2.5.2/lib/typesmapping.html
Re: A Pythonic way to do MapReduce using hadoop
#4Great overview, from top to bottom. Just wondering, is it better performance-wise to explicitly check for key membership than to rely on exceptions? Existing: for line in sys.stdin: name, marks = line.rstrip().split('\t') try: if agregatedmarks.get(name): agregatedmarks.get(name).append(marks) else: agregatedmarks[name] = [marks] except ValueError: pass Or for line in sys.stdin: name, marks = line.rstrip().split('\t'…
aggregatedmarks.setdefault(name,[]).append(marks) See http://docs.python.org/release/2.5.2/lib/typesmapping.html