get の第二引数に初期値の配列を渡しておく
( some_dict.get('some_key', [])
)
people = {'family': ['alice','bob','carol']}
for person in people.get('family', []):
print(person)
# alice
# bob
# carol
for person in people.get('workers', []):
print(person)
# (nothing)
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。