Question: how to convert list1 to list2?

```
list1 =[[1, 11], [2, 22], [3, 33], [4, 44]]
list2 = [[{1:2},{11:22}],[{3:4},{33:44}]]

```

key of list 2 is odd elements of list1, while value of list2 is even number of list1

I've tried like below, but get different list3.

```
def f(list1):

    newlist=[]
    for i in range(0, len(list1), 2):
        dict1={}
        for j,key in enumerate (list1[i]):
            dict1[key]=list1[i+1][j]
            newlist.append(dict1)  
    print newlist

f(list1)
[{1: 2, 11: 22}, {1: 2, 11: 22}, {33: 44, 3: 4}, {33: 44, 3: 4}]

```

Answer: 
As list comprehension:

```
list1 = [[1, 11], [2, 22], [3, 33], [4, 44]]
list2 = [[{tup[0]: tup[1]} for tup in zip(*list1[i:i+2])] for i in range(0, len(list1), 2)]
# Prints as [[{1: 2}, {11: 22}], [{3: 4}, {33: 44}]]

```

---

Edit: This one's a bit cleaner (and more pythonic perhaps).

```
list2 = [[dict([tup]) for tup in zip(*sublist)] for sublist in zip(list1[0::2], list1[1::2])]

```

---

Edit2: The list comprehension is equivalent to this nested for-loop.

```
list1 =[[1, 11], [2, 22], [3, 33], [4, 44]]
list2 = list()

# Iterate over list1 two by two, first round: sublist = ([1,11], [2,22])
for sublist in zip(list1[0::2], list1[1::2]):

    inner_result = list()

    # Second loop equivalent to for tup in zip(sublist[0], sublist[1])
    for tup in zip(*sublist):  # First round, tup will be (1,2) then (11, 22)    

        # Make dictionary from tuple, for first tuple this is
        # equivalent to: dict([(1,2)]) == {1: 2}
        new_dict = dict([tup])  
        inner_result.append(new_dict)

    list2.append(inner_result)

```
Your code is almost correct. The issue is here:

```
dict1={}
for j,key in enumerate (list1[i]):
  dict1[key]=list1[i+1][j]
  newlist.append(dict1)

```

In loop you're using the same dict. So to achieve what you want just move `dict1` definition into the loop (create a new dict on each iteration):

```
for j,key in enumerate (list1[i]):
  dict1={}
  dict1[key]=list1[i+1][j]
  newlist.append(dict1)

```