I want to find range of numbers between ith
, ith + 1
elements of a list, for example, given a list [1, 3, 5, 7]
, I want to return range(1,3), range(3,5), range(5, 7)
. Is there a better way to doing this?
See my code below, it works but I want to assume its not efficient because each loop check if its the last item in the list, any better way to do this?
df = pd.read_csv('file.csv')
itemList = df['A'].values.tolist()
for idx, value in enumerate(itemList):
if itemList[idx]!= itemList[-1]:
print range(value, itemList[idx + 1])