I have a list a for which I want to change the elements a[i: j] according to a function f. Can I do better than the naive way?
for index in range(i, j):
a[index] = f(a)
[By better I mean something closer to map(f, a), or something faster.]
You can assign to the slice:
a[i:j] = map(f, a[i:j])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With