Colors = ["yellow", "red", "green"]
I'm looking for new way to given the latest element of list. Is there a way without using of index [-1]?
Colors = ["yellow", "red", "green"]
I'm looking for new way to given the latest element of list. Is there a way without using of index [-1]?
 
    
    Providing more context would help, as you could simply use Colors[len(Colors) - 1], but that still uses indexing. Another solution would be Colors.pop(), but keep in mind it will remove the last element.
 
    
    In python, list class provides a function pop(),
You can use Colors.pop()
 
    
    How about this?
last = None
for x in Colors:
    last = x
print last
