Check if a value comes before another in a list
<p>I would like to check whether a value comes before another in a list. I asked this question awhile back: <a href="http://stackoverflow.com/questions/38603449/typeerror-githubiterator-object-does-not-support-indexing">TypeError: &#39;GitHubIterator&#39; object does not support indexing</a>, which allows me to access the last comment in a list.  I would like to expand this to look through all the comments in a pull request check whether <code>#hold-off</code> comment comes after the <code>#sign-off comment</code>.  I can print the comments using the print statement but, but it errors out looking at the order of the values with the error message: <code>AttributeError: 'IssueComment' object has no attribute 'index'</code>.</p>

<p>I think I need to somehow get the body of the comments to a list, and then use index to determine the order, because the iterator does not support indexing. But I've been unsuccessful in getting that to work. </p>

<pre><code>hold_off_regex_search_string = re.compile(r"\B#hold-off\b", re.IGNORECASE)
sign_off_regex_search_string = re.compile(r"\B#sign-off\b", re.IGNORECASE)
for comments in list(GitAuth.repo.issue(prs.number).comments()):
    print (comments.body)
    if comments.index(hold_off_regex_search_string.search(comments.body)) &gt; comments.index(sign_off_regex_search_string.search(comments.body)):
        print('True')
</code></pre>

<p>It looks like you're confusing yourself. The <code>for</code> loop is already iterating over the comments in order. All you need to do is test each comment for the <code>#hold-off</code> and <code>#sign-off</code> patterns and report on which one you see first.</p>

<pre><code>hold_off_regex_search_string = re.compile(r"\B#hold-off\b", re.IGNORECASE)
sign_off_regex_search_string = re.compile(r"\B#sign-off\b", re.IGNORECASE)
special_comments = []
for comments in list(GitAuth.repo.issue(prs.number).comments()):
    if hold_off_regex_search_string.search(comments.body):
        special_comments.append('HOLD OFF')
    elif sign_off_regex_search_string.search(comments.body):
        special_comments.append('SIGN OFF')
if special_comments == ['HOLD OFF', 'SIGN OFF']:
    # add label
elif special_comments == ['SIGN OFF', 'HOLD OFF']:
    # remove label
elif special_comments == ['HOLD OFF']:
    # handle it
elif special_comments == ['SIGN OFF']:
    # handle it
elif special_comments == []:
    # handle it
else:
    # maybe multiple sign offs or hold offs?
</code></pre>

python indexing