how to find previous in python