Add the last two elements, append them.
This commit is contained in:
parent
9b10d747b9
commit
5898682bae
|
@ -355,6 +355,26 @@ elif len(lst) % 2 == 0:
|
||||||
print(middle_element([5, 2, -10, -4, 4, 5, 7]))
|
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
|
### Sublists
|
||||||
|
|
||||||
Grab a subset of a list using `sublist = letters[1:6]` This would give you index **1-5**.
|
Grab a subset of a list using `sublist = letters[1:6]` This would give you index **1-5**.
|
||||||
|
|
Loading…
Reference in New Issue