Question: I want that when I click on `id` it sends my value in `id=arxidia` and when I click again on mounoxilo it removes it.

```
<div class="poutsa" id="mounoxilo1" value="vizia1">etsi1</div>
<div class="poutsa" id="mounoxilo2" value="vizia2">etsi2</div>
<div class="poutsa" id="mounoxilo3" value="vizia3">etsi3</div>
<div class="poutsa" id="mounoxilo4" value="vizia4">etsi4</div>

<input type="text" id="arxidia">

```

Answer: 
Imperative is more Pythonic here:

```
d = defaultdict(lambda: [])
for school in a, b, c:
    for g in school['grades']:
        d[g].append(school)

```

Here's the "functional" approach, but as predicted it is not pretty:

```
fst = lambda (x,_): x
grade_to_school = ((g,x) for x in a,b,c for g in x['grades'])
d = { g : list(y) for g,y in groupby(sorted(grade_to_school, key=fst), key=fst) }

```
Where this is so specific, I would suggest making a function for the operation.

```
def AddSchoolsByGrades(schools_by_grades, school_dict):
    # if there is a space in the name, it will take the last word of the name
    name = school_dict["name"].split(" ")[-1]
    for g in school_dict["grades"]:
        # if there is no entry for the grade, then make one
        if not g in schools_by_grades.keys():
            schools_by_grades[g] = []
        # add the name of the school to the grade
        schools_by_grades[g].append(name)
        # simple trick to remove any duplicates
        schools_by_grades[g] = list(set(schools_by_grades[g]))

a = {'name': 'school a', 'grades': [3, 4, 5]}
b = {'name': 'school b', 'grades': [3, 4, 5]}
c = {'name': 'school c', 'grades': [6, 7, 8]}

schools_by_grades = {}
AddSchoolsByGrades(schools_by_grades, a)
AddSchoolsByGrades(schools_by_grades, b)
AddSchoolsByGrades(schools_by_grades, c)

```