Guidance needed - making sense of the inputs


Hi all,

I’m new to Codingame and even though I already solved a couple puzzles, I still have a hard time understanding the inputs of the game.

For instance, in the puzzle I’m currently solving, the console looks like this:

> import sys
> import math

> # Auto-generated code below aims at helping you parse
> # the standard input according to the problem statement.

> n = int(raw_input())  # Number of elements which make up the association table.
> q = int(raw_input())  # Number Q of file names to be analyzed.
> for i in xrange(n):
>     # ext: file extension
>     # mt: MIME type.
>     ext, mt = raw_input().split()
> for i in xrange(q):
>     fname = raw_input()  # One file name per line.

How am I reading this? Are ‘ext’ and ‘mt’ the keys of a dictionary, and if not how can I isolate them into one? If I call xrange(n), will that call n then ext and mt on separate lines, or only ext and mt?

The game description helps understand what all the variables refer to, however I still struggle to visualize what I’m starting with. Any advice on how to get better at this?

Thanks a ton !


CG is passing you n pairs of extension -> MIME type

Example ext=“txt”,mt=“Text file”

It’s up to you to take those pairs and put them in, for example, a dictionary with the ext values as keys and the mt values as values.


for i in xrange(n):
   ext, mt = raw_input().split()

Then you use you dictionary to solve the problem of assiging a MIME type such as “Text file” to every “fname”

[corrected the Python 2 syntax]


As a general note, the starting input code will never auto-create collection objects for you like Arrays, Lists, Sets, Hashes, etc. It only creates loops that read in one entry at a time, so those inputs will be overwritten each time through the loop. The first thing you need to do in most puzzles is figure out what collection data structures make sense for the puzzle, and implement them. Like Agade did in their example.


Thanks a lot @Agade and @Mixolyde, it helps!! I probably missed the first few explanations when I started the game, this raw_input thing was very confusing to me :slight_smile:


No problem, it confused me the first few times, too. I think it would be nice if the default code had a comment above any line that processed list items saying something like this:
// capture list input for n here:
n = Int.parse(stdin.readLineSync())