def nodes_or_number(which_args):
 @decorator
 def _nodes_or_number(f, *args, **kw):
  try:
   iter_wa = iter(which_args)
  except TypeError:
   iter_wa = (which_args,)
  new_args = list(args)
  for i in iter_wa:
   n = args[i]
   try:
    nodes = list(range(n))
   except TypeError:
    nodes = tuple(n)
   else:
    if (n < 0):
     msg = ('Negative number of nodes not valid: %i' % n)
     raise nx.NetworkXError(msg)
   new_args[i] = (n, nodes)
  return f(*new_args, **kw)
 return _nodes_or_number

def nodes_or_number ( which_args ) : @ decorator def _nodes_or_number ( f , * args , ** kw ) : try : iter_wa = iter ( which_args ) except TypeError : iter_wa = ( which_args , ) new_args = list ( args ) for i in iter_wa : n = args [ i ] try : nodes = list ( range ( n ) ) except TypeError : nodes = tuple ( n ) else : if ( n < 0 ) : msg = ( 'Negative number of nodes not valid: %i' % n ) raise nx . NetworkXError ( msg ) new_args [ i ] = ( n , nodes ) return f ( * new_args , ** kw ) return _nodes_or_number
decorator to allow number of nodes or container of nodes .