3
Write your own generator function which works as the internal enumerate function. Using the function thus:
lessons = ["Why Python Programming", "Data Types and Operators", "Control Flow", "Functions", "Scripting"]
for i, lesson in my_enumerate(lessons, 1):
print("Lesson {}: {}".format(i, lesson))
should result in the exit:
Lesson 1: Why Python Programming
Lesson 2: Data Types and Operators
Lesson 3: Control Flow
Lesson 4: Functions
Lesson 5: Scripting
" So guys, I’m having a really hard time on this subject(Generators), I can’t understand how I can solve this problem , I believe I should use the function enumerate() , but my lack of understanding of the subject is compromising my attempts. "
lessons = ["Why Python Programming", "Data Types and Operators", "Control Flow", "Functions", "Scripting"]
def my_enumerate(iterable, start=0):
# Implement your generator function here
for i, lesson in my_enumerate(lessons, 1):
print("Lesson {}: {}".format(i, lesson))
You can include which error is preventing you from succeeding with the code?
– user93774
@Williamlio actually I’m not even able to think how I should create this code , I repeat , because I don’t understand the subject related to generators .
– Cleomir Santos
When I first read it, I understood something very different, when I reread it. I found it very interesting. I’ll keep an eye out, I also want to know the answer ;)
– Barbetta
@Barbetta , me too, I’m not in any way able to find or come up with a code to solve this.
– Cleomir Santos