What would be a more efficient way to do the following:
directors = get_element_or_none(title_node, 'Director')
producers = get_element_or_none(title_node, 'Producer')
writers = get_element_or_none(title_node, 'Writer')
if directors:
directors = [director.strip() for director in directors.split(',')]
if producers:
producers = [producer.strip() for producer in producers.split(',')]
if writers:
writers = [writer.strip() for writer in writers.split(',')]
To always produce a list (possibly empty):
or use
map(str.strip, ...):but in Python 3 that requires an explicit call to
list():because
map()returns an iterator instead.or use a helper function:
or, with the map version:
The split-and-strip operation could probably be merged into one function with the
get_element_or_none()call, but that depends on what else you might use thetolist()functionality for.