Hey, I’m doing the career path for “Data Scientist”, and currently loving python.
I’ve got to the list challenge section:
https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-lists/articles/python-code-challenges-lists
What I like doing is comparing my code with what Codecademy gives if you’re struggling for the solution.
Challenge 1: Append Sum
My code:
def append_sum(lst = []):
lst = lst
for i in range(3):
a, b = lst[-1:-3:-1]
lst.append(a + b)
return lst
CodeCademy:
def append_sum(last):
lst.append(lst[-1] + lst[-2])
lst.append(lst[-1] + lst[-2])
lst.append(lst[-1] + lst[-2])
return lst
I’m curious what is the better code and thought this would be a good chance to communicate with the Codecademy community to get some positive criticism for improving.