|
|
|
|
|
by lolinder
652 days ago
|
|
Hmm, I actually prefer Kotlin's version, but maybe that's just because it's what I'm used to: (0..10).flatMap { x -> (0..10).map { y -> x * y } }
The flow of the data is more intuitive for me because you don't use variables before they're defined.> Especially the yield keyword, such a wonderful way to write your own iterators. Maybe I'm missing something about `yield` in Python—can it do something that Kotlin generators can't? |
|
In py, for list/set/dictionary/generator comprehensions, the format is always the same and always the same as if you were to do it as a normal nested loop, save for the statement being first instead of last (you can also do filters using normal if statement syntax, these go at the end/after all your loops).
I actually like statement first because it gets to the "meat" of the semantics before the context (which loop etc), but end do the day it's all a bit arbitrary
@ yield, there's literally no difference between Python and kotlin. Python also offers a generator comprehension, which is nice, but it has nothing to do with yield
i_am_a_generator = ( x+1 for x in range(10*100) )