Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

AppylPye Group Title

Mechanical MOOC OCW Exercise 2.7 Working With Lists Solution: cumulative_sum.py Here's a solution to the cumulative_sum exercise - 2 versions - the second function using a list comprehension. Does anyone else have a solution to post, so that we can compare different approaches? http://ideone.com/x38UtA

  • one year ago
  • one year ago

  • This Question is Closed
  1. AlbionsRefuge Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Thanks Appyl - I'm happy (and surprised) to report that my solution, with the exception of my variable names, is virtually the same as yours. I'm glad you explained that what the second function was doing involved list comprehensions - I'll have to pick that apart slowly.

    • one year ago
  2. AppylPye Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    In this statement ... return [sum(number_list[:i + 1]) for i in range(len(number_list))] ... each index in "number_list" is considered, by virtue of the fact that "i" takes on values successively matching each index in the list, as specified by the "range" function. As this occurs, the "sum" function returns the sum of all values in the slice of "number_list" that extends from the beginning of the list, up to, and including the value at the index corresponding to the current value of "i".

    • one year ago
  3. AlbionsRefuge Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Thanks for that explanation. I made it to the List comprehensions section and also worked through this http://www.codecademy.com/courses/python-beginner-en-5oLLh-btkJb -- I was surprised at what I could accomplish, and now I would almost call them "fun"!

    • one year ago
  4. AppylPye Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Yes, that Non-track Codecademy List comprehensions course by Iryna Cherniavska is really great - "fun" - yes :)

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.