Decode ascii and reversed words sentence
Use lambdas
def f(a,b):return c
can be shortened to
f=lambda a,b:c
(the f=
can also be removed per CGCC site standards)
Remove excess []
s
x.join([a for b in c])
can be
x.join(a for b in c)
since join can take a generator instead of a list
Split is on spaces by default
Thanks ElPedro for reminding me about this
So the split(' ')
s can be shortened, which in turn means the s=' '
doesn't help (and it only broke even in the first place).
Take input from STDIN and output to STDOUT
print
will automatically print arguments with space as a separator if you use *
to unpacks the sequence/collection into positional arguments, and taking input via input()
is shorter. Also, setting s
to space doesn't actually save any bytes.
Altogether, this is 79 bytes:
print(*[w[::-1]for w in(''.join(chr(int(c))for c in input().split()).split())])
Try it online!
or, if you're dedicated to having a function, 82 bytes:
lambda m:' '.join(w[::-1]for w in(''.join(chr(int(c))for c in m.split()).split()))
Try it online!
plus seven or so characters if you really need the function to be called decode
Python 2, 78 bytes
lambda m:' '.join(x[::-1]for x in''.join(map(chr,map(int,m.split()))).split())
Try it online!
Edit changed to a Python 2 answer as the lambda
is shorter than the print
/input
version in Python 2.
This uses a couple of map
s to get the list of characters which we then join
on "", split
again on space, reverse each element then rejoin
again on space for 78. Also works in Python 3.
Just a pity that it needs so many brackets :-(
Python 3, 75 bytes
lambda a:' '.join(''.join(map(chr,map(int,a.split())))[::-1].split()[::-1])
Try it online!
Python 3, 70 bytes
If taking input from STDIN and outputing to STDOUT is fine then it takes only 70 bytes this is mostly because the spread operator (*
) is shorter than ' '.join()
print(*''.join(map(chr,map(int,input().split())))[::-1].split()[::-1])
Try it online!