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.
You may be right, but I like to avoid boilerplate whenever possible. In my opinion it enhances readability to use situational syntactic sugar like this: because it can only be used in certain circumstances, its use highlights that you are in those circumstances.
Perfectly servicable and efficient. Wouldn't best practices encourage adding a
return
line? Obviously not necessary for such simple code.You can save one byte by using an operator different from the
!=
, but it's not well defined whether or not that's the desired behaviour, and I don't want to take any steps towards turning this into a solution remotely resemblinglambda*_:532
. If you make a fork that changes something other than that and improve the rules in a way that allows a shorter operator to be used, it might be a good thing to copmare against a hypothetical one byte shorter version of this that utilizes the<
operator.Yeah in JS yesterday it took me about an hour to get it working, but way too slow! Still haven't been able to improve it. May need to start over.
It took me about an hour to write it in Python mostly because I was having a difficult time returning the solution even as I was able to print it.
What took me the longest time was to rewrite it in C++ as that is the language that I wanted to solve it.
Still there's the same problem with Python3, there's print() expression issue in test,
as well as another one i get, if needed:
Traceback (most recent call last):
File "main.py", line 14, in
testAndPrint(decodeMorse(decodeBits('1')), 'E')
File "/home/codewarrior/solution.py", line 6, in decodeMorse
return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' '))
File "/home/codewarrior/solution.py", line 6, in
return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' '))
File "/home/codewarrior/solution.py", line 6, in
return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' '))
KeyError: '1'
This comment is hidden because it contains spoiler information about the solution
Done.
no,
sum
just happens to accept a generator. Thatord(c) for c in ...
is a generator expression, and is not a list.ord(c) for c in s.replace(' ', '')- I thought this semantic is for list comprehension, can i use it for every loop?
A generator expression gives the values (in this case the integers coming from
ord(c)
) one by one, instead of storing them in a list.You're right, asymptotically it doesn't change anything.
But a string takes much less space than a list of the same size so we're using at least two times less memory.
But I'm nitpicking, honestly I just removed the brackets because it looks nicer that way.
str.replace
hasO(n)
space complexity, so you're not really saving much.Can you please explain what is a generator expression?
Quite right. I never used this before but it works like a charm.
Loading more items...