def letter_form_to_array_form(array_form, group):
 a = list(array_form[:])
 new_array = []
 n = 1
 symbols = group.symbols
 for i in range(len(a)):
  if (i == (len(a) - 1)):
   if (a[i] == a[(i - 1)]):
    if ((- a[i]) in symbols):
     new_array.append(((- a[i]), (- n)))
    else:
     new_array.append((a[i], n))
   elif ((- a[i]) in symbols):
    new_array.append(((- a[i]), (-1)))
   else:
    new_array.append((a[i], 1))
   return new_array
  elif (a[i] == a[(i + 1)]):
   n += 1
  else:
   if ((- a[i]) in symbols):
    new_array.append(((- a[i]), (- n)))
   else:
    new_array.append((a[i], n))
   n = 1

def letter_form_to_array_form ( array_form , group ) : a = list ( array_form [ : ] ) new_array = [ ] n = 1 symbols = group . symbols for i in range ( len ( a ) ) : if ( i == ( len ( a ) - 1 ) ) : if ( a [ i ] == a [ ( i - 1 ) ] ) : if ( ( - a [ i ] ) in symbols ) : new_array . append ( ( ( - a [ i ] ) , ( - n ) ) ) else : new_array . append ( ( a [ i ] , n ) ) elif ( ( - a [ i ] ) in symbols ) : new_array . append ( ( ( - a [ i ] ) , ( - 1 ) ) ) else : new_array . append ( ( a [ i ] , 1 ) ) return new_array elif ( a [ i ] == a [ ( i + 1 ) ] ) : n += 1 else : if ( ( - a [ i ] ) in symbols ) : new_array . append ( ( ( - a [ i ] ) , ( - n ) ) ) else : new_array . append ( ( a [ i ] , n ) ) n = 1
this method converts a list given with possible repetitions of elements in it .