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 6003911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:11:18+00:00 2026-05-23T01:11:18+00:00

Why am I getting this error, from line 5 of my code, when attempting

  • 0

Why am I getting this error, from line 5 of my code, when attempting to solve Project Euler Problem 11?

for x in matrix:
    p = 0
    for y in x:
        if p < 17:
            currentProduct = int(y) * int(x[p + 1]) * int(x[p + 2]) * int(x[p + 3])
            if currentProduct > highestProduct:
                print(currentProduct)
                highestProduct = currentProduct
        else:
                break
            p += 1
'generator' object is not subscriptable
  • 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-23T01:11:19+00:00Added an answer on May 23, 2026 at 1:11 am

    Your x value is is a generator object, which is an Iterator: it generates values in order, as they are requested by a for loop or by calling next(x).

    You are trying to access it as though it were a list or other Sequence type, which let you access arbitrary elements by index as x[p + 1].

    If you want to look up values from your generator’s output by index, you may want to convert it to a list:

    x = list(x)
    

    This solves your problem, and is suitable in most cases. However, this requires generating and saving all of the values at once, so it can fail if you’re dealing with an extremely long or infinite list of values, or the values are extremely large.

    If you just needed a single value from the generator, you could instead use itertools.islice(x, p) to discard the first p values, then next(...) to take the one you need. This eliminate the need to hold multiple items in memory or compute values beyond the one you’re looking for.

    import itertools
    
    result = next(itertools.islice(x, p))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am getting this error on this code (this is an MVC project into which
What are the most common reasons that I would be getting this error from
Anyone getting this error when using the new free chart controls MS bought from
I'm trying to use slime from CVS (2009-01-05) but keep getting this error: LOAD:
to is not defined [Break on this error] setTimeout('updateChat(from, to)', 1); I'm getting this
im getting this error: Parse error: syntax error, unexpected T_ECHO in /home/labvc/public_html/AT/site/getimages.php on line
I am getting this error on the following code, and cant figure out why.
I am getting this error in my code now: Warning: mysql_num_rows(): supplied argument is
I'm getting this error when running this code: Fatal error: Uncaught exception 'DOMException' with
Anybody can help me with this code I am getting this error message: Server

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.