parameters: (input_string, random_shuffle=False)
return_statement: return permute_string(input_string, permutation)
docstring: Shuffle the characters of input_string so that the least number of letters are in the same
      position as in the original string. For that purpose, constructs a permutation based on letters
      occurrences in the input string. Starting with the least occurring letters, the permutation is
      an alternating sequence of the previous permutation string and the next letter.
      Then the permutation string is translated to indices permutation and the shuffled string is
      constructed.
      A tuple of the
           <input_string, new_shuffled_string, score(input_string, new_shuffled_string)>
      is returned, where the score is the sum of letters that didn't change position in the shuffled
      string.
      :param input_string(str): The input string to shuffle.
      :return: The input string (str), the shuffled string (str) and the score (int) of this shuffle.
docstring_summary: Shuffle the characters of input_string so that the least number of letters are in the same
      position as in the original string. For that purpose, constructs a permutation based on letters
      occurrences in the input string. Starting with the least occurring letters, the permutation is
      an alternating sequence of the previous permutation string and the next letter.
      Then the permutation string is translated to indices permutation and the shuffled string is
      constructed.
      A tuple of the
           <input_string, new_shuffled_string, score(input_string, new_shuffled_string)>
      is returned, where the score is the sum of letters that didn't change position in the shuffled
      string.
      :param input_string(str): The input string to shuffle.
      :return: The input string (str), the shuffled string (str) and the score (int) of this shuffle.
docstring_tokens: Shuffle the characters of input_string so that the least number of letters are in the same position as in the original string . For that purpose constructs a permutation based on letters occurrences in the input string . Starting with the least occurring letters the permutation is an alternating sequence of the previous permutation string and the next letter . Then the permutation string is translated to indices permutation and the shuffled string is constructed . A tuple of the <input_string new_shuffled_string score ( input_string new_shuffled_string ) > is returned where the score is the sum of letters that didn t change position in the shuffled string . : param input_string ( str ) : The input string to shuffle . : return : The input string ( str ) the shuffled string ( str ) and the score ( int ) of this shuffle .
function: def best_shuffle(input_string, random_shuffle=False):
      """
      Shuffle the characters of input_string so that the least number of letters are in the same
      position as in the original string. For that purpose, constructs a permutation based on letters
      occurrences in the input string. Starting with the least occurring letters, the permutation is
      an alternating sequence of the previous permutation string and the next letter.
      Then the permutation string is translated to indices permutation and the shuffled string is
      constructed.
      A tuple of the
           <input_string, new_shuffled_string, score(input_string, new_shuffled_string)>
      is returned, where the score is the sum of letters that didn't change position in the shuffled
      string.
      :param input_string(str): The input string to shuffle.
      :return: The input string (str), the shuffled string (str) and the score (int) of this shuffle.
      """
  
      sorted_letter_count = get_sorted_letter_count(input_string)
  
      if len(sorted_letter_count) <= 1:
          return input_string, input_string, len(input_string)
  
      if random_shuffle:
          sorted_letter_count = shuffle_same_count_letters(sorted_letter_count)
  
      letter, letter_count = sorted_letter_count[0]
      permutation = letter * letter_count
  
      for letter, letter_count in sorted_letter_count[1:]:
  
          permutation = add_letter_to_permutation(permutation, letter*letter_count)
  
  
  
      return permute_string(input_string, permutation)
function_tokens: def best_shuffle ( input_string , random_shuffle = False ) : sorted_letter_count = get_sorted_letter_count ( input_string ) if len ( sorted_letter_count ) <= 1 : return input_string , input_string , len ( input_string ) if random_shuffle : sorted_letter_count = shuffle_same_count_letters ( sorted_letter_count ) letter , letter_count = sorted_letter_count [ 0 ] permutation = letter * letter_count for letter , letter_count in sorted_letter_count [ 1 : ] : permutation = add_letter_to_permutation ( permutation , letter * letter_count ) return permute_string ( input_string , permutation )