Git Product home page Git Product logo

Comments (3)

reuven avatar reuven commented on June 24, 2024

Ah, good catch! Yes, my plan was that it would work like the built-in enumerate, working just like enumerate does with a single argument, except that the index would start with whatever number you gave. So it should indeed start with 2 and a, rather than 2 and c. I'm not sure if it's a mistake in my implementation, or in what I showed.

I'm delighted that you're enjoying the book! If you have a few moments to write a review on Amazon.com (even a short one!), that would be super helpful and appreciated.

from python-workout.

daviddoji avatar daviddoji commented on June 24, 2024

This is how I implemented to have such a behavior:

class MyEnumerate_indexed:
    def __init__(self, data, start=0):
        self.data = data
        self.index = start

    def __iter__(self):
        return MyEnumerateIterator(self.data, self.index)


class MyEnumerateIterator:
    def __init__(self, data, start=0):
        self.data = data
        self.index = start
        # to keep track of the index
        self.init = start

    def __next__(self):
        if self.index >= len(self.data) + self.init:
            raise StopIteration
        value = (self.index, self.data[self.index - self.init])
        self.index += 1
        return value

from python-workout.

reuven avatar reuven commented on June 24, 2024

Yup, looks good!

from python-workout.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.