For the usual case, when you want the first element, you can do
next(iter([1, 2, 3]), None)
I use this to “expand” the list, perhaps after filtering it.
next((x for x in [1, 3, 5] if x % 2 == 0), None)
or
cur.execute("SELECT field FROM table") next(cur.fetchone(), None)
Pepijn Mar 26 '14 at 17:49 2014-03-26 17:49
source share