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:

  1. Double each number (i.e. value) in y, and replace the key with the letter corresponding to the new number.

  2. Do the same for z, but triple each number instead.

  3. Populate a dictionary x with the keys and values from both y and z in descending numerical order, for instance:

x = {'x': 24, 'n':18, 'm': 14, 'l':12, 'j': 10, 'f': 6, 'b':2}

Good luck!


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}
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Mego Aug 28 '18 at 0:51

Python, 174 155 113 86 70 68 66 bytes

It's actually my first time here and here's my attempt. Let me know if I am doing anything wrong.

lambda y,z:{chr(v*(3-v%2)+96):v*(3-v%2)for v in{**y,**z}.values()}

EDIT: After OP's edit and @Rod 's comment I noticed I have some mistakes. I also took out the sorting attempts because it simply can't work with Python dictionaries.

EDIT2: -16bytes thanks to @JonathanAllan

Try it online!

  • \$\begingroup\$ Just so you know, at the moment this is a TIPS question, not a challenge. Please add an explanation to your answer. \$\endgroup\$ – mbomb007 Aug 24 '18 at 19:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.