Question: ```
import csv

price = []
score = []
numPrice = []
numScore = []
with open(r'C:\Users\Testing\Desktop\Test.csv') as f:
    reader = csv.DictReader(f)
    for row in reader:
        price.append(row['price'])
        score.append(row['helpfulness_score'])
    for item in price:
        numPrice.append(float(item))
    for item in score:
        numScore.append(float(item))
finalDict = dict(zip(numScore,numPrice))                

for k in finalDict:
    if k > 5:
        finalDict.pop(k)

```

How can I remove all key and values less than 5?
Right now I get the error 'RuntimeError: dictionary changed size during iteration'
And is there a way to make this more efficient?

Answer: 
For starters the vector should be passed to the function by reference. Otherwise a redundant copy of the vector will be created. Moreover the parameter should be declared with constant reference because the vector itself is not changed in the function.

For the sum you should use the type `long long int` because it is not excluded that there can be an overflow.

This declaration

```
int length = sizeof(ar);

```

does not make sense. The variable `length` keeps the size of the object of the type `std::vector<int>` not the number of elements stored in the vector.

So the function can be defined for example the following way

```
long long int simpleArraySum( const std::vector<int> & ar )
{
    long long int sum = 0;

    for ( const auto &item : ar ) sum += item;

    return sum;
}

```

Another approach is to use the standard algorithm `std::accumulate` declared in the header `<numeric>`. For example

```
#include <vector>
#include <iterator>
#include <numeric>

//...

long long int simpleArraySum( const std::vector<int> & ar )
{
    return std::accumulate( std::begin( ar ), std::end( ar ), 0ll );
}

```
Use [`std::accumulate`](https://en.cppreference.com/w/cpp/algorithm/accumulate):

```
int simpleArraySum(vector<int> ar) {
    return std::accumulate(ar.begin(), ar.end(), 0);
}

```

In any case, your `length` initialization is wrong, it should be:

```
int length = ar.size();

```

If you are still having unexpected results, it is likely that you are either under/overflowing `sum` (likely, use a wider type) or that you have too many elements to fit in an `int` (unlikely, switch to `std::size_t` or use a range-for loop instead).