In python Decode a checkerboard Define a function named decoder_damier that accepts as argument a checkerboard represented as a string, and returns a tuple  (m,n,k) where m and n are respectively the number of rows and columns of the checkerboard, and k is a dictionary of the tokens that are on this checkerboard. A token is defined as any character other than '.', the latter symbolizing an empty checkerboard. The returned dictionary must contain key associations: value where the key is a couple (i,j)  Row and column indices of the block of the token with a value symbol. For example, the following expression: decoder_damier('..A....... n.B........ nC......... n.......... n') must return the following tuple: (4, 10, {(0, 2): 'A', (1, 1): 'B', (2, 0): 'C'}) That is, a checkerboard of 4 rows by 10 columns, with tokens A, B and C respectively in boxes  (0.2) ,  (1.1)  and  (2.0). Note that your function must not make any display, only return the requested tuple. You can assume that the string received as argument contains no white space, that the lines are separated by n and that they all have exactly the same number of characters. You can also assume that m 1 and n 1 . To solve this problem, we suggest you: Using str.splitlines. Initialize an empty dictionary for tokens. Loop on the checkerboard lines (think of enumerate). Loop on the characters of each line. If a character differs from '.', then add it to the token dictionary. Return the tuple requested.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

In python

Decode a checkerboard
Define a function named decoder_damier that accepts as argument a checkerboard represented as a string, and returns a tuple  (m,n,k) where m and n are respectively the number of rows and columns of the checkerboard, and k is a dictionary of the tokens that are on this checkerboard. A token is defined as any character other than '.', the latter symbolizing an empty checkerboard. The returned dictionary must contain key associations: value where the key is a couple (i,j)  Row and column indices of the block of the token with a value symbol.

For example, the following expression:

decoder_damier('..A....... n.B........ nC......... n.......... n')
must return the following tuple:

(4, 10, {(0, 2): 'A', (1, 1): 'B', (2, 0): 'C'})
That is, a checkerboard of 4 rows by 10 columns, with tokens A, B and C respectively in boxes  (0.2) ,  (1.1)  and  (2.0).

Note that your function must not make any display, only return the requested tuple. You can assume that the string received as argument contains no white space, that the lines are separated by n and that they all have exactly the same number of characters. You can also assume that m 1 and n 1 .

To solve this problem, we suggest you:

Using str.splitlines.
Initialize an empty dictionary for tokens.
Loop on the checkerboard lines (think of enumerate).
Loop on the characters of each line.
If a character differs from '.', then add it to the token dictionary.
Return the tuple requested.

Expert Solution
Step 1

Description:

Define the function decoder_damier as follows:

  • Initialize an empty tuple and dictionary.
  • Use the splitlines function to split the input string str based on the new line character and store it in a list l.
  • Set row and column values to the length of l and length of l[0] respectively.
  • Use a for loop to iterate over each value in l:
    • Set x to l[i].
    • Use a for loop to iterate over each character in x:
      • If the current character is not '.', add the character to the dictionary such that the key is its exact position and the value is the character.
  • Add the values of the rowcolumn, and dict to the resultant tuple.
  • Return the resultant tuple.
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY