if else in dictionary comprehension code example

Example 1: types of dict comprehension

# Dictionary Comprehension Types

{j:j*2 for i in range(10)}

#using if 
{j:j*2 for j in range(10) if j%2==0}

#using if and 
{j:j*2 for j in range(10) if j%2==0 and j%3==0}

#using if else
{j:(j*2 if j%2==0 and j%3==0 else 'invalid' )for j in range(10) }

Example 2: if else in dictionary comprehension python

{ (some_key if condition else default_key):(something_if_true if condition
          else something_if_false) for key, value in dict_.items() }

Example 3: dictionary comprehension python

print({i:j for i,j in zip(txt_list,num) if i!="All"})