Changeset 2105


Ignore:
Timestamp:
Jan 2, 2010 1:50:12 AM (10 years ago)
Author:
wehart
Message:

Adding an xsequence() function, which mimics xrange.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/base/util.py

    r2094 r2105  
    9191    return range(args[0],args[1]+1,args[2])
    9292
     93def xsequence(*args):
     94    """
     95    xsequence([start,] stop[, step]) -> xrange object
     96   
     97    Like sequence(), but instead of returning a list, returns an object that
     98    generates the numbers in the sequence on demand.  For looping, this is
     99    slightly faster than sequence() and more memory efficient.
     100    """
     101    if len(args) == 0:
     102        raise TypeError, 'xsequence expected at least 1 arguments, got 0'
     103    if len(args) > 3:
     104        raise TypeError, 'xsequence expected at most 3 arguments, got %d' % len(args)
     105    if len(args) == 1:
     106        return xrange(1,args[0]+1)
     107    if len(args) == 2:
     108        return xrange(args[0],args[1]+1)
     109    return xrange(args[0],args[1]+1,args[2])
    93110
Note: See TracChangeset for help on using the changeset viewer.