python - How do I find a previous element in a list? -


n = 2 list1 = [1,4,6,2,8,9,90] 

how go finding number prior number n stored above in list1 , store in variable list1_result?

this should work:

list1 = [1,4,6,2,8,9,90] n = 2 ind = list1.index(n) list1_result = list1[ind-1] # 6 

Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -