write it in python Write a function called yank_middle, which takes a list and r
ID: 3798403 • Letter: W
Question
write it in python
Write a function called yank_middle, which takes a list and returns the item in the middle of the list, and removes that item from the list when it does. So it behaves a bit like the list pop() method. When there are an even number of items in the list, the "middle" is ambiguous. Just have it pick the earlier of the two. Examples: yank_middle((10, 50, 3, 8)) returns 50. yank_middle(['cow', bird', 'spider', 'horse', elephant']) returns 'spider'.. 3. 83) returns 58. yank_middle(['com', 'bird', 'spider', 'horse'. 'elephant']) returns 'spider'.Explanation / Answer
def yank_middle(v):
l = len(v)
l = l-1
l =int(l/2)#finding center index
a = v[l]#storing center value
del v[l]#removiing from list
return a#returning center value
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.