#K73007. Counting Occurrences in a List
Counting Occurrences in a List
Counting Occurrences in a List
You are given a list of integers and a target integer. Your task is to count the occurrences of the target in the list in a cumulative way. More specifically, for every index i such that L[i] == target, you need to output a key-value pair where the key is i and the value is the number of times the target has appeared in the list up to and including index i.
For example, if the list is [7, 7, 7, 7, 7] and the target is 7, then the output should be:
If the target is not present in the list, output an empty dictionary: {}
. The indices in the output should be in increasing order.
inputFormat
The input is read from stdin in the following format:
- An integer
n
, the number of elements in the list. - A line containing
n
space-separated integers representing the list. - An integer representing the target value.
outputFormat
Output the dictionary (in Python-style format) that maps each index where the target is found to the cumulative count of occurrences up to that index. The output is printed to stdout.
## sample5
1 2 3 4 5
3
{2: 1}