+ 2
How can I generate using "yield" the data from that list in that order
7 Réponses
+ 3
for i in c:
print(next(spell(txt)))
+ 1
Alejandro47
Fix identation error at line 8
0
Identation it'snt enough
0
That fix it
0
But I didn't understand why because they don't teach me that function yet
0
Alejandro47
# Hi! You can take a look at this one, build on your ideas:
def spell_func(txt): # Design generator.
for c in txt:
yield c.upper()
# Use generator, eihter in this way:
s = "hello"
spell = spell_func(s) # Create generator.
try:
while True:
print(spell.__next__())
except StopIteration:
print("")
# Or in this way:
s2 = "world"
spell = spell_func(s2) # Create generator.
for c in spell: # Using' inbuild __next__'.
print(c)
# Or at this one:
https://code.sololearn.com/cwpnhdc32l6s/?ref=app
0
Alejandro47 , mean you haven't gone through this yet, is that your homework?
There are tons of ways to solve this, I showed you the easiest way to fix your code, not solve it.