Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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

Lists & Dictionaries
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
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.
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".
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"!

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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

Not the answer you are looking for?

Search for more explanations.

Ask your own question