Skip to content

Instantly share code, notes, and snippets.

@maryrosecook
Created December 9, 2014 20:16
Show Gist options
  • Save maryrosecook/9d9ea2ae96559b06da49 to your computer and use it in GitHub Desktop.
Save maryrosecook/9d9ea2ae96559b06da49 to your computer and use it in GitHub Desktop.
bands = [{'name': 'sunset rubdown', 'country': 'UK', 'active': False},
{'name': 'women', 'country': 'Germany', 'active': False},
{'name': 'a silver mt. zion', 'country': 'Spain', 'active': True}]
def assoc(_d, key, value):
from copy import deepcopy
d = deepcopy(_d)
d[key] = value
return d
def set_canada_as_country(band):
return assoc(band, 'country', "Canada")
def strip_punctuation_from_name(band):
return assoc(band, 'name', band['name'].replace('.', ''))
def capitalize_names(band):
return assoc(band, 'name', band['name'].title())
print pipeline_each(bands, [set_canada_as_country,
strip_punctuation_from_name,
capitalize_names])
# Implement pipeline_each so that the pipeline_each call
# above returns:
# => [{'name': 'Sunset Rubdown', 'active': False, 'country': 'Canada'},
# {'name': 'Women', 'active': False, 'country': 'Canada' },
# {'name': 'A Silver Mt Zion', 'active': True, 'country': 'Canada'}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment