# Python Built-in Function next()

**URL:** <https://forums.plex.tv/t/python-built-in-function-next/125293>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [November 29, 2015, 12:13am UTC](https://forums.plex.tv/t/python-built-in-function-next/125293 "2015-11-29T00:13:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Twoure](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/twoure/32/91016_2.png) [@Twoure](https://forums.plex.tv/u/Twoure)\
**Post date:** [November 29, 2015, 12:13am UTC](https://forums.plex.tv/t/python-built-in-function-next/125293/1 "2015-11-29T00:13:13Z")

</div>

Trying to use Python 2.7 Built-in Function [next()](https://docs.python.org/2.7/library/functions.html#next) but keep getting a NameError

```auto
NameError: global name 'next' is not defined

```

test code:

```auto
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,

```auto
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?

---

<div class="post-metadata">

**Author:** ![coryo123](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@coryo123](https://forums.plex.tv/u/coryo123)\
**Post date:** [November 29, 2015, 4:36am UTC](https://forums.plex.tv/t/python-built-in-function-next/125293/2 "2015-11-29T04:36:28Z")

</div>

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

couldn’t you just write

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

```

---

<div class="post-metadata">

**Author:** ![Twoure](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/twoure/32/91016_2.png) [@Twoure](https://forums.plex.tv/u/Twoure)\
**Post date:** [November 29, 2015, 5:28am UTC](https://forums.plex.tv/t/python-built-in-function-next/125293/3 "2015-11-29T05:28:13Z")

</div>

@coryo123 no that would not work for my application.

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

```auto
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']`

```json
{
    '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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 8, 2020, 7:53pm UTC](https://forums.plex.tv/t/python-built-in-function-next/125293/4 "2020-01-08T19:53:22Z")

</div>

Closed on January 8, 2020, 7:53pm UTC


