First page Back Continue Last page Overview Graphics

Exercises

Write a list comprehension, which generates all possible combinations of two dice.

comb = [(i,j) for i in range(1,7) for j in range(1,7)]

Write a list comprehension which inverses a given dictionary, i.e.

the values will be keys and the keys will be turned into values.

>>> dir = {'DE':'Deutschland','FR':'Frankreich'}

>>> inv = dict((dir[i],i) for i in dir)

>>> print(inv)

{'Deutschland': 'DE', 'Frankreich': 'FR'}

>>>