Python Built-in Function next()

Trying to use Python 2.7 Built-in Function next() but keep getting a NameError

NameError: global name 'next' is not defined

test code:

test_list = list(xrange(5))
test = next((i for i in test_list if i == 3), False)

should return 3 or False

I gather that the built-in function next() is not included in Plex Media Server’s custom Python? Or is it and I’m just accessing/using it incorrectly?

Update
Found this to work,

test_list = list(xrange(5))
test = (i for i in test_list if i == 3).next()

but now I cannot set a default and will get a StopIteration error if the test_list does not include 3.
I want this to stay as one line, so I cannot use try: except: to account for the StopIteration error

Any ideas?

there are a few built-in functions that are missing in Plex.

couldn’t you just write

test = 3 if 3 in xrange(5) else False

@coryo123 no that would not work for my application.

So here’s what I ended up doing, it works for me.

bm = Dict['Bookmarks']
genre = 'News'
if ((True if [b['id'] for b in bm[genre] if b['id'] == video_info['id']] else False) if genre in bm.keys() else False) if bm else False:
    #do stuff

example Dict['Bookmarks']['News']

{
    'News': {[
        {'title': 'New Channel', 'summary': 'test sum', 'id': 'channel id #'},
        {'title': 'Next Channel', 'summary': 'test sum 2', 'id': 'channel id #2'}
    ]}
}

I wanted a one line test to know if the Bookmark id existed within the genre. I don’t need the b['id'] returned, I just need to know if it exist within my bookmarks.