def _convert_to_svm_node_array(x):
 import operator
 iter_range = []
 if (type(x) == dict):
  for (k, v) in x.iteritems():
   iter_range.append(k)
 elif operator.isSequenceType(x):
  for j in range(len(x)):
   iter_range.append(j)
 else:
  raise TypeError, 'data must be a mapping or a sequence'
 iter_range.sort()
 data = svmc.svm_node_array((len(iter_range) + 1))
 svmc.svm_node_array_set(data, len(iter_range), (-1), 0)
 j = 0
 for k in iter_range:
  svmc.svm_node_array_set(data, j, k, x[k])
  j = (j + 1)
 return data

def _convert_to_svm_node_array ( x ) : import operator iter_range = [ ] if ( type ( x ) == dict ) : for ( k , v ) in x . iteritems ( ) : iter_range . append ( k ) elif operator . isSequenceType ( x ) : for j in range ( len ( x ) ) : iter_range . append ( j ) else : raise TypeError , 'data must be a mapping or a sequence' iter_range . sort ( ) data = svmc . svm_node_array ( ( len ( iter_range ) + 1 ) ) svmc . svm_node_array_set ( data , len ( iter_range ) , ( - 1 ) , 0 ) j = 0 for k in iter_range : svmc . svm_node_array_set ( data , j , k , x [ k ] ) j = ( j + 1 ) return data
convert a sequence or mapping to an svm_node array .