Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

previous value list loop python

a_list = [1,2,3,4,5]

for index, elem in enumerate(a_list):
    if (index+1 < len(a_list) and index - 1 >= 0): #Check index bounds

        prev_el = str(a_list[index-1])
        curr_el = str(elem)
        next_el = str(a_list[index+1])

        print(prev_el, curr_el, next_el)
Comment

list loop get previous element

a_list = [1,2,3,4,5]

for index, elem in enumerate(a_list):
    if (index+1 < len(a_list) and index - 1 >= 0):
Check index bounds

        prev_el = str(a_list[index-1])
        curr_el = str(elem)
        next_el = str(a_list[index+1])

        print(prev_el, curr_el, next_el)
Comment

PREVIOUS NEXT
Code Example
Python :: py pause script 
Python :: flask marshmallow 
Python :: networkx create graph from dataframe 
Python :: calcolatrice online 
Python :: python change base function 
Python :: python string remove whitespace and newlines 
Python :: remove jupyter environment 
Python :: plt axis tick color 
Python :: python get time difference in milliseconds 
Python :: python dictionary get keys with condition on value 
Python :: transparancy argument pyplot 
Python :: colored text python 
Python :: django foreign key error Cannot assign must be a instance 
Python :: saving a pandas dataframe as a csv 
Python :: run code at the same time python 
Python :: add download directory selenium python 
Python :: tkinter draw squaer 
Python :: sum of 1 to n number in python 
Python :: check dictionary is empty or not in python 
Python :: Extract Date from Datetime object 
Python :: read tsv file column 
Python :: factorial recursion python 
Python :: download files requests python 
Python :: python get the key with the max or min value in a dictionary 
Python :: django print settings 
Python :: python initialize dictionary with lists 
Python :: how to install python libraries 
Python :: python - count number of values without dupicalte in a second column values 
Python :: pandas new df from groupby 
Python :: how to add up everything in a list python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =