#๐Ÿ”’ Why is there no output in the last option

12 messages ยท Page 1 of 1 (latest)

pine cedar
#

a = enumerate('YouTube')
print(a) #outputs : <enumerate object at 0x000001D2F6327290>

print(list(a))
# outputs : [(0, 'Y'), (1, 'o'), (2, 'u'), (3, 'T'), (4, 'u'), (5, 'b'), (6, 'e')]

for j, item in list([(0, 'Y'), (1, 'o'), (2, 'u'), (3, 'T'), (4, 'u'), (5, 'b'), (6, 'e')]):
print(j, item)
outputs :
0 Y
1 o
2 u
3 T
4 u
5 b
6 e

for k, ktem in list(a):
print(k, ktem)

**NO OUTPUT
**

verbal oarBOT
#

@pine cedar

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

verbal oarBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

hoary basalt
#

enumerate objects are generators, once you use them they're gone

#

so when you have print(list(a)), this effectively consumes a, if you remove that print statement you'll find that your last for loop should work

pine cedar
#

i see

#

yes it worked ! thanks

stray jackal
#

*Iterator, not generator.

#

You can't send an enumerate object, for example.

verbal oarBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.