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

  • Home
  • SEARCH
  • 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 6634007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:52:46+00:00 2026-05-25T22:52:46+00:00

I am accessing an element of length 2 tuple by tuple_name[0] but the python

  • 0

I am accessing an element of length 2 tuple by tuple_name[0] but the python interpreter keeps giving me error Index out of bounds.

Here is the code for reference:

def full(mask):
    v = True
    for i in mask:
        if i == 0:
            v = False
    return v

def increment(mask, l):
    i = 0
    while (i < l) and (mask[i] == 1):
        mask[i] = 0
        i = i+1
    if i < l:
        mask[i] = 1

def subset(X,Y):
    s = len(X)
    mask = [0 for i in range(s)]
    yield []
    while not full(mask):
        increment(mask, s)
        i = 0
        yield ([X[i] for i in range(s) if mask[i]] , [Y[i] for i in range(s) if mask[i]])

x = [100,12,32]
y = ['hello','hero','fool']

s = subset(x,y)  # s is generator

for a in s:
    print a[0]   # Python gives me error here saying that index out of 
                 # bounds, but it runs fine if I write "print a".
  • 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-05-25T22:52:47+00:00Added an answer on May 25, 2026 at 10:52 pm

    Changing the final line to simply print a and running the exact code you’ve pasted above, I get the following output:

    []
    ([100], ['hello'])
    ([12], ['hero'])
    ([100, 12], ['hello', 'hero'])
    ([32], ['fool'])
    ([100, 32], ['hello', 'fool'])
    ([12, 32], ['hero', 'fool'])
    ([100, 12, 32], ['hello', 'hero', 'fool'])
    

    So, quite clearly, the first iteration is an empty list, so does not have an element 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question might seem silly, but what's the difference between accessing an element (with
I am having trouble accessing the data field. I receive the error: Databinding methods
Is there a way of accessing the width of a DOM element? In particular,
I am creating a list, and then accessing an element like this: list =
Accessing an html element's current style using Element.currentStyle only exists in IE. Is there
I am having trouble accessing the value of an HTML Input element using jQuery,
I am having trouble accessing both the Class and the current element. How can
Accessing an array element with the following line works great; if (dataset[i].properties.property == value)
When accessing an element in an array the square brackets are used like so:
I am stuck with as issue of accessing HTML element in IE using XPath

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.