def _flatten_artist_credit(credit):
 artist_parts = []
 artist_sort_parts = []
 artist_credit_parts = []
 for el in credit:
  if isinstance(el, basestring):
   artist_parts.append(el)
   artist_credit_parts.append(el)
   artist_sort_parts.append(el)
  else:
   alias = _preferred_alias(el['artist'].get('alias-list', ()))
   if alias:
    cur_artist_name = alias['alias']
   else:
    cur_artist_name = el['artist']['name']
   artist_parts.append(cur_artist_name)
   if alias:
    artist_sort_parts.append(alias['sort-name'])
   elif ('sort-name' in el['artist']):
    artist_sort_parts.append(el['artist']['sort-name'])
   else:
    artist_sort_parts.append(cur_artist_name)
   if ('name' in el):
    artist_credit_parts.append(el['name'])
   else:
    artist_credit_parts.append(cur_artist_name)
 return (''.join(artist_parts), ''.join(artist_sort_parts), ''.join(artist_credit_parts))

def _flatten_artist_credit ( credit ) : artist_parts = [ ] artist_sort_parts = [ ] artist_credit_parts = [ ] for el in credit : if isinstance ( el , basestring ) : artist_parts . append ( el ) artist_credit_parts . append ( el ) artist_sort_parts . append ( el ) else : alias = _preferred_alias ( el [ 'artist' ] . get ( 'alias-list' , ( ) ) ) if alias : cur_artist_name = alias [ 'alias' ] else : cur_artist_name = el [ 'artist' ] [ 'name' ] artist_parts . append ( cur_artist_name ) if alias : artist_sort_parts . append ( alias [ 'sort-name' ] ) elif ( 'sort-name' in el [ 'artist' ] ) : artist_sort_parts . append ( el [ 'artist' ] [ 'sort-name' ] ) else : artist_sort_parts . append ( cur_artist_name ) if ( 'name' in el ) : artist_credit_parts . append ( el [ 'name' ] ) else : artist_credit_parts . append ( cur_artist_name ) return ( '' . join ( artist_parts ) , '' . join ( artist_sort_parts ) , '' . join ( artist_credit_parts ) )
given a list representing an artist-credit block .