Ask Question
2 December, 23:58

The slice_gen generator takes one iterable and a start, stop and step values (all int, with the same meanings as the values in a slice: [start:stop:step], except start and stop must be non-negative and step must be positive; raise an Assetio nerror exception if any is not). It produces all the values in what would be the slice (without every putting all the values in a list and slicing it). For example

+4
Answers (1)
  1. 3 December, 02:17
    0
    See Explaination

    Explanation:

    def slice_gen (iterable, start, stop, step):

    it = iter (iterable)

    if start < 0 or stop < 0 or step < = 0:

    raise Assertio nerror

    count = - 1

    nextI = start

    while True:

    count + = 1

    try:

    item = next (it)

    if count = = stop:

    break

    elif count = = nextI:

    nextI = nextI + step

    yield item

    except:

    return

    for i in slice_gen ('abcdefghijk', 3, 7, 1):

    print (i, end='')

    print ("")
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The slice_gen generator takes one iterable and a start, stop and step values (all int, with the same meanings as the values in a slice: ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers