Question: I am trying to rewrite the MATLAB code below into Python, and found that my Python code (2.7 sec) is slower than MATLAB (1.2 sec).
I have tried many different ways, including the module numba, but no luck yet.
How can I make the Python code faster?

MATLAB code:
============

```matlab
szA=[1024,1280]; HfszA=[512,640];
[aPx,aPy]=meshgrid(-HfszA(2):HfszA(2)-1,-HfszA(1):HfszA(1)-1);
img=randi(255,1024,1280);
fx=rand(); fy=rand();
tic
for i=1:20
    F=abs(sum(sum(img.*exp(-1i*2*pi*(fx*aPx+fy*aPy)))));
end
toc

```

Python code:
============

```
import numpy as np
import time

szA=[1024,1280]; HfszA=[512,640]
aPx,aPy=np.meshgrid(np.arange(-HfszA[1],HfszA[1]),np.arange(-HfszA[0],HfszA[0]))
img=np.array(np.random.randint(256,size=(1024,1280)))

fx=np.random.rand()
fy=np.random.rand()

start = time.time()
for i in range(20):
    F=abs(np.sum(img*np.exp(-1j*2*np.pi*(fx*aPx+fy*aPy))))
end = time.time()
print("Elapsed (after compilation) = %s" % (end - start))
print(F)

```

Answer: 
do you mean that?

```
[(key, value) for key, values in l1.items() for value in values]

```

that results in 

```
[(2, 'tag1'), (2, 'tag2'), (3, 'tag2')]

```

(where is your `'tag3'` from?)
This should do the job;

```
l1 = {1: [],  
      2: ["tag1", "tag2"],
      3: ["tag2"])

l2 = []
for key, values in l1.items():
    new_values = []
    for value in values:
        new_values.append(value)
    l2.append(tuple(new_values))

>>> l2
[(2, "tag1"), (2, "tag2"), (3, "tag2")]

```