user_ids = { "John": 12, "Anna": 2, "Jack": 10 } # bad practice name = "Paul" if name in user_ids: user_id = user_ids[name] else: user_id = None # good practice user_id = user_ids.get(name, None)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter