dict list comprehension python code example
Example 1: create dictionary comprehension python
{key:value for key in iterable}
Example 2: dictionary comprehension python
square_dict = {num: num*num for num in range(1, 11)}
Example 3: types of dict comprehension
{j:j*2 for i in range(10)}
{j:j*2 for j in range(10) if j%2==0}
{j:j*2 for j in range(10) if j%2==0 and j%3==0}
{j:(j*2 if j%2==0 and j%3==0 else 'invalid' )for j in range(10) }
Example 4: dictionary comprehension python
print({i:j for i,j in zip(txt_list,num) if i!="All"})
Example 5: dict comprehension
{j:j*2 for i in range(10)}