* Questions
V Mysteries
V list index error
* nums = [1,2,3,4,5]
print(nums[5])
V read/write list
* nums = [0, 1, 2, 3, 4]
for i in range(1, len(nums)):
nums[i] = nums[i-1]
print(nums)
V concatenation
* nums1 = [1, 2, 3]
nums2 = [4, 5, 6]
print(nums1 + nums2)
* msg1 = ["The", "rebels,", "sir"]
msg2 = ["they're", "here"]
print(msg1 + msg2)
V Practice
V write a function sum that takes a list of numbers and returns the sum of those numbers
* accumulator variable
* Python has as a built-in sum function
V Mystery
V list of lists
*
data = [[1,2],[3,4],[5,6]]
acc = 0
for x in data:
for num in x:
acc = acc + num
print(acc)
V Practice
V write a function is_sorted that takes a list and returns True if the elements are in ascending order
* for i in range(len(nums)) loops over the indexes of nums
V write a function cumulative_sum that takes a list of numbers and returns a new list where each element is the sum of the elements of the original list up to that point
* use my_list.append(x) to add x to the end of my_list