this post was submitted on 16 Oct 2023
7 points (88.9% liked)

Python

6401 readers
18 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

The thing I love about python is it's elegance; and I thing that is partially due to its syntactic sugar. Between list comprehensions, destructuring, enumerators, generators with yield, and a bunch more, what is your favorite

you are viewing a single comment's thread
view the rest of the comments
[–] Walnut356 8 points 1 year ago (2 children)

Generators probably. It's the one thing i genuinely miss about python when i work in rust.

[–] lavafroth 1 points 1 year ago (1 children)
[–] tatterdemalion 3 points 1 year ago (1 children)

That's not quite the same as a generator. Iterators require explicit returns to yield control, and this involves dropping the entire stack frame.

True generators allow one to yield, which pauses the function and allows it to be resumed. The most similar thing to this in Rust is an async block/fn, but there is ongoing effort to generalize this so you could create an iterator from a generator.

[–] lavafroth 1 points 1 year ago
[–] [email protected] 1 points 1 year ago

You're right. Having just yield sth in a function instead of defining the data structure is such a game changer.