Ask Question
26 April, 09:10

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

+3
Answers (1)
  1. 26 April, 12: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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers