Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:36:53+00:00 2026-06-07T14:36:53+00:00

I have a list containing booleans: my_list = [False, False, False, True, True, True]

  • 0

I have a list containing booleans:

my_list = [False, False, False, True, True, True]

I want to evaluate if for a given tuple with (start, end) indexes the list contains a True value, e.g.

contains_true(my_list, (0,0)) => False
contains_true(my_list, (0,2)) => False
contains_true(my_list, (0,3)) => True
contains_true(my_list, (3,5)) => True
contains_true(my_list, (5,5)) => True

Currently I’m doing this:

def contains_true(my_list, indexes_tuple):
    start = indexes_tuple[0]
    end = indexes_tuple[1] + 1
    indexes = range(start, end)

    for i in indexes:
        if my_list[i]:
            return True
    return False

Is there a better way to do this in Python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:36:55+00:00Added an answer on June 7, 2026 at 2:36 pm
    >>> my_list = [False, False, False, True, True, True]
    >>> def contains_true(seq, bounds):
            start, end = bounds
            return any(seq[start:end+1])
    
    >>> contains_true(my_list, (0,0))
    False
    >>> contains_true(my_list, (0,2))
    False
    >>> contains_true(my_list, (0,3))
    True
    >>> contains_true(my_list, (3,5))
    True
    >>> contains_true(my_list, (5,5))
    True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list. It contains x lists, each with y elements. I want
If I have a list containing [alice, bob, abigail, charlie] and I want to
I have a List containing elements that are accessed according to their indexes. In
I have a list containing three columns. The first column contains Names and the
I have a list containing a tuples and long integers the list looks like
I have a list containing version strings, such as things: versions_list = [1.1.2, 1.0.0,
I have a list containing about 1000 file names to search under a directory
Say I have a list containing strings that look like this: 00x000s00g00wfds0d dkdf00sdf00sdfg00jk kf00dfjkd0sdl0sd0f0
I have a dropdown list containing the days of the week - Monday to
I have a stl::list containing Widget class objects. They need to be sorted according

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.