def dmp_swap(f, i, j, u, K):
 if ((i < 0) or (j < 0) or (i > u) or (j > u)):
  raise IndexError(('0 <= i < j <= %s expected' % u))
 elif (i == j):
  return f
 (F, H) = (dmp_to_dict(f, u), {})
 for (exp, coeff) in F.items():
  H[((((exp[:i] + (exp[j],)) + exp[(i + 1):j]) + (exp[i],)) + exp[(j + 1):])] = coeff
 return dmp_from_dict(H, u, K)

def dmp_swap ( f , i , j , u , K ) : if ( ( i < 0 ) or ( j < 0 ) or ( i > u ) or ( j > u ) ) : raise IndexError ( ( '0 <= i < j <= %s expected' % u ) ) elif ( i == j ) : return f ( F , H ) = ( dmp_to_dict ( f , u ) , { } ) for ( exp , coeff ) in F . items ( ) : H [ ( ( ( ( exp [ : i ] + ( exp [ j ] , ) ) + exp [ ( i + 1 ) : j ] ) + ( exp [ i ] , ) ) + exp [ ( j + 1 ) : ] ) ] = coeff return dmp_from_dict ( H , u , K )
transform k[ .