Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 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
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

AlbionsRefuge Group TitleBest ResponseYou've already chosen the best response.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

AppylPye Group TitleBest ResponseYou've already chosen the best response.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

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

AppylPye Group TitleBest ResponseYou've already chosen the best response.1
Yes, that Nontrack Codecademy List comprehensions course by Iryna Cherniavska is really great  "fun"  yes :)
 one year ago
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
 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.