|
|
|
|
|
by Larrikin
658 days ago
|
|
As someone who uses Kotlin for work and Python for side projects (and loved Python years ago in college), Python's list comprehension feature is one of the things I hate the most about the language now. As a simple example using only two collection functions I find it much easier to read val hundredOrLessEvenSeconds = (1..1000)
.toList()
.filter { it <= 100 }
.filter { it % 2 == 0 }
.map { it.seconds }
than hundred_or_less_even_seconds = [timedelta(seconds=it) for it in range(1, 1001) if it <= 100 and it % 2 == 0]
But there are tons of helper functions in the collections library to express that in a variety of different ways. But not in a gross code golf way, with clearly named functionsTheres just so much built in
https://kotlinlang.org/docs/collections-overview.html Having lambdas built into the language from the start leads to a ton of expressibility I miss when using python |
|