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) }

```
You could do:

```
schools_by_grades = {i: [school['name'] for school in (a, b, c) 
                         if i in school['grades']] 
                     for i in range(20) if any(i in school['grades'] 
                                               for school in (a, b, c))}

```

but you probably shouldn't.

This gives me:

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

```