I have a list of integers a and I want to iterate through every element of it, and if the element is smaller or the same size as the next element in the list (the upcoming index-neighbour), I want to convert the element into a string and concatenate "000" onto it. But if it's larger than the next element, I want to concatenate "111" onto it.
I use Python 3.7.3.
Here's what I've already tried:
a = [41433, 23947, 10128, 89128, 29523, 47106]
for I in a:
if a[I] <= a[I+1]:
a[I] = str(a[I] + "000")
else:
a[I] = str(a[I] + "111")
I've actuallly tried a lot more than that, but nothing worked. When I run the code, I always get "IndexError: list index out of range".
I'm quite new in Python, anyone know a solution?
for i in range(len(a)-1): a[i] = str(a[i]) + ('000' if a[i] <= a[i+1] else '111')