10
0
In a challenge of CodingGame, there is a challenge that ask you to decode a string composed by reversed words ('Hello world' > 'olleH dlrow') then each characters converted into ascii value separeted by space:
>>> decode('111 108 108 101 72 32 100 108 114 111 119 32 41 58')
Hello world :)
The challenge is to be the fastest to write the decode
function, but I later tried to write it with the fewest character possible.
Here is my result (104 characters):
def decode(m,s=' '):return s.join([w[::-1]for w in(''.join([chr(int(c))for c in m.split(s)]).split(s))])
The name of the function doesn't matter, it can be shorter, but only rename variable isn't good enough for an answer.
Is it possible to improve this result ?
Does the function have to be called
decode
? Is a specific version required? Can the output contain whitespace that isn't spaces, and if so, how should it be handled? – xnor – 2019-12-20T11:45:52.337This part is obviously longer than a 'd' or something else, and does not required any knowledge, so I don't care (the "Take input from STDIN and output to STDOUT" part of the Jo King answer is pertinent). It must contain the ascii character '32'. – Dorian Turba – 2019-12-20T11:52:49.570
1
To clarify, is this challenge limited to only Python? Also is I/O restricted to a function that takes as input an ASCII space character delimited string? Not Default I/O methods?
– 640KB – 2020-02-20T16:56:08.490This challenge is ok for default I/O method, but I'm new to this SE, sorry. I will edit the questions since all answer provide the default solution too. And thanks for the link about "default I/O methods! – Dorian Turba – 2020-02-21T00:02:33.813