Add the last two elements, append them.

This commit is contained in:
Josh Mudge 2019-01-11 23:59:49 -07:00
parent 9b10d747b9
commit 5898682bae
1 changed files with 20 additions and 0 deletions

View File

@ -355,6 +355,26 @@ elif len(lst) % 2 == 0:
print(middle_element([5, 2, -10, -4, 4, 5, 7]))
```
### Add the last two elements, append them. (Ex.8)
```
def append_sum(lst):
trip = 0
while trip < 3:
lasttwo = lst[-2:]
added = lasttwo[0] + lasttwo[1]
print(added)
lst.append(added)
trip = trip + 1
return lst
#Uncomment the line below when your function is done
print(append_sum([1, 1, 2]))
```
### Sublists
Grab a subset of a list using `sublist = letters[1:6]` This would give you index **1-5**.