Years ago when I started to learn python after switching from JS and C++ (both at pretty basic level) and I wonder why python’s built-in features for lists look so hideous. Just an example:
If I want to modify, filter and then get sum of some list in python it will look like:
some_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
result = sum(filter(lambda x: x % 2, map(lambda x: x * 3 + 1 if x % 2 else x // 2, some_list)))
Which looks at least less readable then JS code, because operations are done from inside to outside, basically, from right to left which is very inconvinient. Let’s look at some JS (I know how bad JS is but for my example it is perfect)
let some_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
some_list
.map(x => x % 2 ? x * 3 + 1: x / 2)
.filter(x => x % 2)
.reduce((a,b) => a + b)
A couple of weeks ago I tried to recreate this functionality with custom class and it took me at most 4 hours to make it happen. So my question is: “Why python does not support it out of the box?”