1
New to code golf and enjoying it. I have a problem that I cannot figure out and am curious if others can solve it.
Start with two dictionaries, y
and z
:
y = {'a': 1, 'c': 3, 'e': 5, 'g': 7}
z = {'b': 2, 'd': 4, 'f': 6, 'h': 8}
y
and z
both map length-1 strings to numbers, where each number is between 1 and 26 (inclusive) and represents an English letter: a = 1, b = 2, c = 3, d = 4 , ... , z = 26.
The goal is as follows:
Double each number (i.e. value) in
y
, and replace the key with the letter corresponding to the new number.Do the same for
z
, but triple each number instead.Populate a dictionary
x
with the keys and values from bothy
andz
in descending numerical order, for instance:
x = {'x': 24, 'n':18, 'm': 14, 'l':12, 'j': 10, 'f': 6, 'b':2}
Good luck!
Example:
Starting state:
y = {'a': 1, 'c': 3, 'e': 5, 'g': 7}
z = {'b': 2, 'd': 4, 'f': 6, 'h': 8}
After y
operations:
y = {'b':2, 'f': 6, 'j': 10, 'm': 14}
After z
operations:
z = {'f': 6, 'l': 12, 'n': 18, 'x': 24}
Comments are not for extended discussion; this conversation has been moved to chat.
– Mego – 2018-08-28T00:51:33.917