All problems

Averaging the A/B Arms

mediumPythonAnalyticsA/B TestingDictionaries

Lantern's experiment platform writes one line per visitor: which arm of the test that visitor landed in, and whether they went on to convert. Assignment is random and the test was stopped mid-week, so the arms are not the same size and a count per arm would say nothing. The arm names are not announced anywhere either — the only way to learn them is to read the log.

Task: Print each arm's conversion rate.

Input

The first line holds an integer n, the number of log lines. Each of the next n lines holds an arm name and a value separated by a single space. The value is 1 if that visitor converted and 0 if not.

Output

One line per arm, in alphabetical order by name: the arm, one space, then its conversion rate as a number between 0 and 1 with exactly three digits after the decimal point. An arm where nobody converted still gets a line, showing 0.000.

Example:

Input:
6
A 1
B 0
A 0
B 1
A 1
B 1

Output:
A 0.667
B 0.667

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…