original_docstring: Voices a chord progression in a specified key using DP.
  
      Follows eighteenth-century voice leading procedures, as guided by the cost
      function defined in the `chordCost` and `progressionCost` functions.
      Returns a list of four-pitch chords, corresponding to successive Roman
      numerals in the chord progression.
      
docstring: Voices a chord progression in a specified key using DP.
  Follows eighteenth-century voice leading procedures, as guided by the cost
  function defined in the `chordCost` and `progressionCost` functions.
  Returns a list of four-pitch chords, corresponding to successive Roman
  numerals in the chord progression.
docstring_tokens: Voices a chord progression in a specified key using DP . Follows eighteenth - century voice leading procedures as guided by the cost function defined in the ` chordCost ` and ` progressionCost ` functions . Returns a list of four - pitch chords corresponding to successive Roman numerals in the chord progression .
code: def voiceProgression(key, chordProgression):
      """Voices a chord progression in a specified key using DP.
  
      Follows eighteenth-century voice leading procedures, as guided by the cost
      function defined in the `chordCost` and `progressionCost` functions.
      Returns a list of four-pitch chords, corresponding to successive Roman
      numerals in the chord progression.
      """
      key = Key(key)
      if isinstance(chordProgression, str):
          chordProgression = list(filter(None, chordProgression.split()))
  
      dp = [{} for _ in chordProgression]
      for i, numeral in enumerate(chordProgression):
          chord = RomanNumeral(numeral, key)
          voicings = voiceChord(key, chord)
          if i == 0:
              for v in voicings:
                  dp[0][v.pitches] = (chordCost(key, v), None)
          else:
              for v in voicings:
                  best = (float("inf"), None)
                  for pv_pitches, (pcost, _) in dp[i - 1].items():
                      pv = Chord(pv_pitches)
                      ccost = pcost + progressionCost(key, pv, v)
                      if ccost < best[0]:
                          best = (ccost, pv_pitches)
                  dp[i][v.pitches] = (best[0] + chordCost(key, v), best[1])
  
      cur, (totalCost, _) = min(dp[-1].items(), key=lambda p: p[1][0])
      ret = []
      for i in reversed(range(len(chordProgression))):
          ret.append(Chord(cur, lyric=chordProgression[i]))
          cur = dp[i][cur][1]
      return list(reversed(ret)), totalCost
code_tokens: def voiceProgression ( key , chordProgression ) : key = Key ( key ) if isinstance ( chordProgression , str ) : chordProgression = list ( filter ( None , chordProgression . split ( ) ) ) dp = [ { } for _ in chordProgression ] for i , numeral in enumerate ( chordProgression ) : chord = RomanNumeral ( numeral , key ) voicings = voiceChord ( key , chord ) if i == 0 : for v in voicings : dp [ 0 ] [ v . pitches ] = ( chordCost ( key , v ) , None ) else : for v in voicings : best = ( float ( "inf" ) , None ) for pv_pitches , ( pcost , _ ) in dp [ i - 1 ] . items ( ) : pv = Chord ( pv_pitches ) ccost = pcost + progressionCost ( key , pv , v ) if ccost < best [ 0 ] : best = ( ccost , pv_pitches ) dp [ i ] [ v . pitches ] = ( best [ 0 ] + chordCost ( key , v ) , best [ 1 ] ) cur , ( totalCost , _ ) = min ( dp [ - 1 ] . items ( ) , key = lambda p : p [ 1 ] [ 0 ] ) ret = [ ] for i in reversed ( range ( len ( chordProgression ) ) ) : ret . append ( Chord ( cur , lyric = chordProgression [ i ] ) ) cur = dp [ i ] [ cur ] [ 1 ] return list ( reversed ( ret ) ) , totalCost
short_docstring: Voices a chord progression in a specified key using DP.
short_docstring_tokens: Voices a chord progression in a specified key using DP .
comment: """Voices a chord progression in a specified key using DP.
  
      Follows eighteenth-century voice leading procedures, as guided by the cost
      function defined in the `chordCost` and `progressionCost` functions.
      Returns a list of four-pitch chords, corresponding to successive Roman
      numerals in the chord progression.
      """