#C9119. Categorize Items by Type
Categorize Items by Type
Categorize Items by Type
You are given a series of items provided as input. Each item can be one of four types: integer, float, string, or boolean. Your task is to count the occurrences of each type and output a dictionary (in Python style) that includes only the types with a nonzero count.
The counting rules are as follows:
- If the token is exactly
True
orFalse
, it is considered a boolean. - If the token contains a dot ('.'), it is interpreted as a float. (Even if it represents an integer value like 1.0, it is still a float.)
- If the token can be parsed as an integer (and does not contain a dot), it is considered an integer.
- Otherwise, the token is treated as a string.
Your final output must be in the format of a Python dictionary. For example, if there are two integers, one float, one string, and one boolean, the output should be:
\(\{ 'integers': 2, 'floats': 1, 'strings': 1, 'booleans': 1 \}\)
inputFormat
The first line of input contains a single integer \(n\) which denotes the number of items.
The following \(n\) lines each contain one item. An item is provided as a token without any extra quotes. Use the following rules:
- If the token is exactly
True
orFalse
, it represents a boolean. - If the token contains a dot ('.'), it represents a float.
- If the token can be parsed as an integer (and does not contain a dot), it represents an integer.
- Otherwise, it is a string.
outputFormat
Output a single line containing the dictionary representation (in Python style) that includes the counts of each type that appear. Only include keys for which the count is nonzero.
## sample5
1
2.0
hello
True
3
{'integers': 2, 'floats': 1, 'strings': 1, 'booleans': 1}