["python"]
Get value at list/array index or "None" if out of range in Python

Is there clean way to get the value at a list index or None if the index is out or range in Python? The obvious way to do it would be this: if len(the_list) > i: return the_list[i] else: return None However, the verbosity reduces code readability. Is there a clean, simple, one-liner that can be used instead?
Try: try: return the_list[i] except IndexError: return None Or, one liner: l[i] if i < len(l) else None Example: >>> l=list(range(5)) >>> i=6 >>> print(l[i] if i < len(l) else None) None >>> i=2 >>> print(l[i] if i < len(l) else None) 2