A community for students.
Here's the question you clicked on:
 0 viewing
AppylPye
 one year ago
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
AppylPye
 one year ago
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

This Question is Closed

AlbionsRefuge
 one year ago
Best ResponseYou've already chosen the best response.1Thanks 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.

AppylPye
 one year ago
Best ResponseYou've already chosen the best response.1In 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".

AlbionsRefuge
 one year ago
Best ResponseYou've already chosen the best response.1Thanks for that explanation. I made it to the List comprehensions section and also worked through this http://www.codecademy.com/courses/pythonbeginneren5oLLhbtkJb  I was surprised at what I could accomplish, and now I would almost call them "fun"!

AppylPye
 one year ago
Best ResponseYou've already chosen the best response.1Yes, that Nontrack Codecademy List comprehensions course by Iryna Cherniavska is really great  "fun"  yes :)
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.