Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
User solved it (I copied View Solution code and started debugging, but passed Attempt on first try) but didn't bother to close Question afterwards -.-
No problems with Python tests therefore & closing Question.
.
In case of
in
it depends on data structure. Hashmap basedset
anddict
don't iterate items (unless everything has the same hash which is extremely unlikely), butlist
andtuple
do.Either author should specify that blatant
for
shouldn't be used or add tests accodringly to your' suggestion.If you don't mind some random drive-by feedback on your code:
Your solution is a prime example of violating the DRY principle. It is 4 times longer than it needs to be. Seeing your kyu level I'm not sure whether you might be doing this on purpose, so disregard if none of this is news to you :)
Specifically, this is regarding the way you do multiple comparisons on the value of
d
. In the context,d
will always be exactly one and only one of the four optionsR
U
D
L
. Inside every if-block, the code is pretty much identical, except for minor details. A way of avoiding repetition, and thus increasing legibility and comprehensibility, would be to bundle up the dependecies (values ofd
) together with the changes they imply. Adict
is perfectly suited for this. There is also always the performance aspect to consider: boolean checks may be fast, but they are not free. Every step, you are performing 4 conditional checks. You can reduce this down to 0. Checking whether the head is out-of-bounds doesn't have to be tailored individually to each value ofd
. There is one valid condition forb
and one valid condition fora
, irrespective ofd
.No(
it is nice to be surprised after submit my code and see a much better solution :)
No problem. Thank you!
Python translation should be fixed, thanks for posting this.
I'm sorry I haven't been on codewars in years. Just found the tab people have been referring to and should be fixed.
I'm sorry I haven't been on codewars in years. Just found the tab people have been referring to and should be fixed.
Sample tests in Python are still wrong.
It is still the same in the sample tests!
Loading more items...