Skip to content

Instantly share code, notes, and snippets.

@walkerdb
Created November 21, 2015 23:05
Show Gist options
  • Save walkerdb/8d3d049dcc1c3ad657fb to your computer and use it in GitHub Desktop.
Save walkerdb/8d3d049dcc1c3ad657fb to your computer and use it in GitHub Desktop.
def split_extents(extent_text):
text_split = extent_text.split(" and ")
extent_list = []
# now that the sentence is split by "and", let's split each of
# the two resulting items by commas, appending the result to
# a new list
for extent in text_split:
extent_list.append(extent.split(","))
# Now we have a list containing two lists: [['3 linear ft.', '1 oversize volume', ''], ['5 motion picture reels']]
# We need to flatten it down to one list. We also need to remove
# trailing whitespace from the front and end of each entry
extent_list_2 = []
for extent_list in extent_list:
for extent in extent_list:
extent_list_2.append(extent.strip(" "))
# the split method left empty strings in the list, so we'll
# use the "filter" function to remove them.
return filter(None, extent_list_2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment