0
\$\begingroup\$

Your task is to create a program will transform each letter of a text typed on a AZERTY keyboard to the equivalent on a QWERTY keyboard, using the same keystrokes.

Example: Hello; Zorld1 => Hello, World!

List of character to convert:

  • A <=> Q
  • Z <=> W
  • , => m
  • ? => M
  • M => :
  • 1 => !
  • 9 => (
  • ; => ,
  • § => ?
  • 0 => )
  • ) => -
  • ù => '

QWERTY keyboard: QWERTY keyboard

AZERTY keyboard: enter image description here

Test cases:

Input: This is q text zritten zith q QWERTY keyboqrd:
Output: This is a text written with a AZERTY keyboard.

Input: Hello zorld in PythonM print9ùHello; Zorld1ù0
Output: Hello world in Python: print('Hello, World!')

Input: Zikipediq is q free online enciclopediq
Output: Wikipedia is a free online enciclopedia

Input: Progrq,,ing puwwles qnd code)golf
Output: Programming puzzles and code-golf

Input: Zhy ,y lqyout hqve szitched to QWERTY §
Output: Why my layout have switched to AZERTY ?

This is code golf, so the answer with the shortest byte count win.

\$\endgroup\$
7
  • 3
    \$\begingroup\$ Could you please explicitly list which character should be replaced by which? \$\endgroup\$
    – flawr
    Commented Jun 28, 2016 at 19:06
  • \$\begingroup\$ @flawr Every character, i'll add this \$\endgroup\$ Commented Jun 28, 2016 at 19:07
  • 3
    \$\begingroup\$ He means an explicit list. Like, A => Q, W => Z, etc. \$\endgroup\$ Commented Jun 28, 2016 at 19:09
  • 2
    \$\begingroup\$ @TùxCräftîñg Can you please add that list? \$\endgroup\$
    – flawr
    Commented Jun 28, 2016 at 19:34
  • 2
    \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ it would seem that valid answers to that challenge would work for this one with minor changes then. So I would agree that it is a dupe. HOWEVER, the other challenge has a lot of restrictions that this one does not. One might argue that this challenge is open to entries from more languages which would be in favor of reopening. \$\endgroup\$
    – Liam
    Commented Jul 1, 2016 at 15:41

1 Answer 1

7
\$\begingroup\$

Python 3, 70 132 bytes

My first try in code-golfing, so please be kind :):

print(input().translate(str.maketrans('azqwAZQW&é"\'(-è_çà)^$Mù,?;:!§1234567890','qwazQWAZ1234567890-[]:\'mM,./?!@#$%^&*()')))

Try it online!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ ; is converted to m, and numbers should also be handled. Oh and put your code in a code element (`code`), not a blockquote ;) \$\endgroup\$ Commented Jun 28, 2016 at 19:24
  • \$\begingroup\$ Should be better now :). \$\endgroup\$
    – DimP
    Commented Jun 28, 2016 at 19:53
  • \$\begingroup\$ you can prolly save with a lambda instead of print/input. \$\endgroup\$
    – Maltysen
    Commented Jun 28, 2016 at 19:54
  • \$\begingroup\$ ValueError: the first two maketrans arguments must have equal length \$\endgroup\$ Commented Jun 28, 2016 at 19:55
  • \$\begingroup\$ No such error on my local installation. I have just added a 'try it online' link. \$\endgroup\$
    – DimP
    Commented Jun 28, 2016 at 20:06

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