On Sat, Feb 20, 2021 at 09:40:48AM -0500, C W wrote: > Hello everyone, > > I'm curious if there is a way take number and back each digit by 3 ? > > 2342 becomes 9019 > 8475 becomes 5142 > 5873 becomes 2540 > > The tricky part is that 2 becomes 9, not -1. > [...]
I just wrote a very short code can fulfill your needs:
a = 2342
b = int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a)))))
It does the following things:
1. Convert a number into a string, and then convert this string into
a list of single characters.
2. Write a lamdba expression to apply your conversion rules to a
single-character type number (just subtract 3 and then modulo 10).
3. Apply the lambda expression to the above string list through map.
4. Finally join the modified list into a string and convert it into an
integer.
--
OpenPGP fingerprint: 3C47 5977 4819 267E DD64 C7E4 6332 5675 A739 C74E
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list
