#πŸ”’ Does this make any sense in python?

31 messages Β· Page 1 of 1 (latest)

hushed temple
rancid cobaltBOT
#

@hushed temple

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.

lost vault
#

not like that no

hushed temple
#

what is the point of this question then i don't understand

oak summit
#

I’m guessing it’s supposed to be part of a list comp? By itself it means nothing

torn salmon
#

its a generator

hushed temple
#

ye?

torn salmon
#

(i**2 for i in range(1, 5))

hushed temple
#

oh

#

so it creates array

torn salmon
hushed temple
#

wym

lost vault
#

it doesn't create an array

#

it creates an generator

hushed temple
#

i never heard about generator

torn salmon
hushed temple
#

okay

#

so it returs some generator object

#

and whats the feature here?

lost vault
#

generators dont hold all its objects in memory, it yields them when you need them

loud bridge
#

@hushed temple Do you understand or do you have any other questions about it?

hushed temple
#

thx

wise grail
#

Generators are like you saying
β€œZ = X + Y” to someone and only a few hours later going
β€œX = 5, Y = 3”
You don’t tell them Z, you just tell them how to get Z

loud bridge
#

Glad you understand. Generators are one of my favorite Pythonic things.

#

If you don't have anymore questions you can type !close on a blank line @hushed temple

#

happy coding

hushed temple
#

!close

rancid cobaltBOT
#
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.