📜  dict 理解的类型 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:11.176000             🧑  作者: Mango

代码示例1
# 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) }