previous value list loop python

Solutions on MaxInterview for previous value list loop python by the best coders in the world

showing results for - "previous value list loop python"
Neele
06 Aug 2017
1a_list = [1,2,3,4,5]
2
3for index, elem in enumerate(a_list):
4    if (index+1 < len(a_list) and index - 1 >= 0): #Check index bounds
5
6        prev_el = str(a_list[index-1])
7        curr_el = str(elem)
8        next_el = str(a_list[index+1])
9
10        print(prev_el, curr_el, next_el)