mylist = range(100)
otherlist = ['21','31','689','777','479','51','71','yut','poi','ger',
'11','61','789','zozozozo','8888','1']
def magic_slicer(iterable,keep,throw):
it = iter(iterable).next
for n in xrange((len(iterable)//keep+throw)+1):
for i in xrange(keep): yield it()
for i in xrange(throw): it()
print list(magic_slicer(mylist,10,20))
print
print list(magic_slicer(otherlist,2,3))
print '__________________'
def magic_slicer2(iterable,keep,throw):
return ( x for i,x in enumerate(iterable) if -1< i%(keep+throw)<keep)
print list(magic_slicer2(mylist,10,20))
print
print list(magic_slicer2(otherlist,2,3))
результат
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
['21', '31', '51', '71', '11', '61', '1']
__________________
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
['21', '31', '51', '71', '11', '61', '1']