|
|
|
|
|
by RodericDay
3742 days ago
|
|
It's actually much more sensible code a lot of the time, especially for people who didn't get a degree that consisted of a lot of for-looping in class. good_jedis = [jedi for jedi in universe if jedi.alignment == "good"]
vs. good_jedis = []
for jedi in universe:
if jedi.alignment == "good":
good_jedis.append(jedi)
And then when you get on stuff like dictionary comprehensions and generator expressions, it starts becoming an amazing tool that is able to accomplish things that are straight-up cumbersome with old loops.There's a computer science course out there that a friend was telling me about, that begins by showing students how to "map" a function over an iterable, way way before a "for loop" ever shows up. I think this is the way it should be done, "for loops" as a three-line-structure only seem natural to people who grew up programming for loops. |
|