slicing an array with offset and limit
<p>i'm migrating some data from SqlAlchemy selects into a cache of item ids.</p>

<p>i'm trying to figure out the best way to handle migrating functions that have a limit and offset attached.</p>

<p>the code i have below works fine. my worry is that it takes 7 lines - and usually when something like this takes a few lines, it's because I'm not seeing something or there's something about Python that I forgot about or haven't learned yet.</p>

<pre><code>def sampling( selection, offset=0 , limit=None ):
    if offset or limit:
        if limit is not None:
            limit = offset + limit        
        else:
            limit = len(selection)
        selection = selection[offset:limit]
    return selection

ids = range(1,100)
print sampling(ids,1,20)
print sampling(ids,10,20)
print sampling(ids,90)
print sampling(ids,90,300)
</code></pre>
