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

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -