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

The Archive Base Latest Questions

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

I was trying to do some of the problems on projecteuler, and I got

  • 0

I was trying to do some of the problems on projecteuler, and I got to the one with the sum of squares and squares of sums. I didn’t want to brute force it, so I looked up the solution, which was:

sum1 = 0
sum2 = 0

for i in ((x,x ** 2) for x in range(1,100+1)):
    sum1 += i[0]
    sum2 += i[-1]

print(sum1 ** 2 - sum2)

I do not get:

(x,x ** 2) for x in range(1,100+1)

I’ve seen this in another code golf solution in javascript too. Is this a specific syntax, or an unfamiliar way of something regular? Can someone please explain?

  • 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:09:30+00:00Added an answer on May 25, 2026 at 10:09 pm

    When confronted with complex syntax, add print statements.

    for i in ((x,x ** 2) for x in range(1,100+1)):
        print i
    

    Not too helpful.

    Try this.

    a = ((x,x ** 2) for x in range(1,100+1))
    print a
    for i in a:
         print i
    

    Helpful? Maybe.

    Try this:

    a = ((x,x ** 2) for x in range(1,100+1))
    b = list(a)
    print b
    

    Hmmm. The for i in a loop stops working, also. This generator object seems to do it’s thing once only. Either in a for loop or in the list() (or tuple()) function but not both.

    Try this.

     for x in range(1,100+1): 
          print x, x**2
    

    Okay. So, what have we learned?

    ((x,x ** 2) for x in range(1,100+1)) is a generator expression. http://www.python.org/dev/peps/pep-0289/

    It’s “iterable” and can be used in a for statement or the list() function.

    Also, we’ve learned to add print statements to explore confusing syntax.

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

Sidebar

Related Questions

I'm having some problems trying to perform a query. I have two tables, one
We've got some problems with an external company trying in integrate into a WCF
I'm trying to solve Project Euler #9, which is http://projecteuler.net/index.php?section=problems&id=9 . I've looked through
I have just started learning Erlang and am trying out some Project Euler problems
I was trying some problems with my 2D ruby array and my LOC reduces
I have been having some problems trying to get my PHP running. When I
I was recently fighting some problems trying to compile an open source library on
I'm having some problems trying to get the code below to output the data
I'm trying to do some browser automation, but I'm having some problems. Basically, what
I've run into some problems when trying to serialize my object to XML. The

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.