You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Understand what the interviewer is asking for by using test cases and questions about the problem.
Do I need to modify the provided function?
No.
P-lan
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create a function to safely get the last element of a list.
1) Create a new function with a parameter for the list
2) If the list is not empty, look for the last element:
a) Find the length of the list
b) Get the element at index length - 1
3) Otherwise, return None
⚠️ Common Mistakes
Why would we look at index "length - 1" instead of just "length"?
I-mplement
# Could also do with looping and a temp variable instead of using lendefget_last(lst):
iflst:
length=len(lst)
returnlst[length-1]
else:
returnNone