Comments (3)
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.
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.
Yup, looks good!
from python-workout.
Related Issues (17)
- [Question]Chapter 10: Exercise 47 beyond the exercise 1 HOT 15
- e05b1_capitalized output will always be as if the word begins with consonant HOT 1
- Chapter 1 Exercise 2 Beyond 1 HOT 2
- Chapter 1 Exercise 2 Beyond 4
- e13b1_namedtuple_records.py throws KeyError
- Can not convert string to int HOT 2
- Unsupported operand type(s) for +: 'int' and 'str' HOT 3
- Missing *
- e05b2_punctuation.py do not return the correct result
- e07b1_capital.py do not check if the first character is a vowel and uppercase HOT 1
- e09b4_even_odd_sums.py should return sum of odd-indexed and even-indexed numbers
- Typo in comment
- e21b1_md5_files.py (calculate the MD5 hash for the contents of every file)
- e12b1_most_repeated_vowels.py gives IndexError if word has no vowels
- wcfile.txt and e20_wc.py miscount
- Solution to problem 19.2 seems to have a bug HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-workout.