3 ms·
This is a really good point. I am very big on making code Pythonic, but I always tell junior developers to get the thing to work first. Once it works, we can r
by dec0dedab0de 5y ago
This is a really good point. I am very big on making code Pythonic, but I always tell junior developers to get the thing to work first. Once it works, we can re-write it with the advantage of hindsight. The hard part is getting people to tell the manager it's going to be a few days longer even though it's already working.
- contravariant 5y agoYeah, though at this point it would help to be a bit more explicit about what we even want. The most consistent interpretation I can come up with as follows: - Partition the list into strictly monotonic runs (either increasing or decreasing) - Reverse the decreasing runs. But writing a version that is entirely bug free turns out to be surprisingly tricky. You also need to be careful about how you allow runs to be split up. You can't require each run to be maximally large because then [1,2,3,4,3,2,1] must be partitioned into overlapping runs. You also can't just require the list to be partition into any set of monotonic runs, because then [[1],[2],[3],[4]] is a valid partition of [1,2,3,4]. This is especially a problem when you allow runs that aren't strictly monotonic.