Skip to main content
fixed error
Source Link
Mizipzor
  • 51.9k
  • 23
  • 98
  • 138

Oneliner:

thefirst = (i[i for i in range(10) if i > 3)[0]3][0]

If youre not sure that any element will be valid according to the criteria, you should enclose this with try/except since that [0] can raise an IndexError.

Oneliner:

thefirst = (i for i in range(10) if i > 3)[0]

If youre not sure that any element will be valid according to the criteria, you should enclose this with try/except since that [0] can raise an IndexError.

Oneliner:

thefirst = [i for i in range(10) if i > 3][0]

If youre not sure that any element will be valid according to the criteria, you should enclose this with try/except since that [0] can raise an IndexError.

Source Link
Mizipzor
  • 51.9k
  • 23
  • 98
  • 138

Oneliner:

thefirst = (i for i in range(10) if i > 3)[0]

If youre not sure that any element will be valid according to the criteria, you should enclose this with try/except since that [0] can raise an IndexError.