Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
非常に頻繁に、次の構造を使用します。
try: x = d[i] except KeyError: x = '?'
ときどき、「?」の代わりに 0 または を使用しますNone。私はこの構造が好きではありません。冗長すぎます。私がしていることを行うためのより短い方法はありますか(1行で)。何かのようなもの。
None
x = get(d[i],'?')
あなたはこれを探しています:
x = d.get(i, '?')