3 ms·
For the example teenagers = people.where(lambda p: 20 >= p.age >= 13) I prefer the good ol' Pythonic way teenagers = filter(lambda p: 13 <= p.age <=
by geoalchimista 8y ago
For the example
teenagers = people.where(lambda p: 20 >= p.age >= 13)
I prefer the good ol' Pythonic way
teenagers = filter(lambda p: 13 <= p.age <= 20, people)
because I know how filter behaves, but am I certain that `where` gives me the elements not their indices (cf. `numpy.where`)?
In another example
ages = people.age
The Pythonic way can be
ages = [p.age for p in people]
Despite having more characters to type, list comprehension is a well-known idiom and I bet many Python programmers would be able to write it down in a second or two.
And how would `old_people.last()` be any clearer than `old_people[-1]`? At least from these examples, I'm not convinced it makes a strong case to switch to the .NET Lists.
- lou1306 8y agoPython also has [p for p in people if 20 >= p.age >= 13] which someone (I, for one) might find more readable than both the proposed `where` method and the `filter` builtin