Reputation: 27
Firstly sorry for my english.I will try to explain my situation.
I have a list and contains numbers as [0...255]. Im trinyg to find numbers in list like this.
[0,7,3,3,55,12...] as you can see numbers 3 same and sequential. I want to find only them not like this [0,7,3,5,3,55,12...]. In this list, there are same numbers but not sequential. I want to add that code to my below code.
if color in images[:-1]:
print("Eşi bulundu",*cards[images.index(color )],"ile",*cards[len(images)-1])
if i%2==0:
esClick(*cards[images.index(color )])
time.sleep(2)
#esClick(*cards[len(images)-1])
#time.sleep(2)
images.insert(images.index(color ), 256)
images.pop(images.index(color ))
images.pop()
images.append(256)
print(images)
I couldnt figure out how to code for this
How can i implement this ? Any help appreciated.
Upvotes: 0
Views: 411
Reputation: 5745
The below code prints a list with (index, index+1, number):
a = [0, 0, 7, 3, 3, 7 ,55, 0, 12, 12]
ans = [(i-1, i, x) for i, x in enumerate(a) if x==a[i-1] and i>0]
print(ans) # --> [(0, 1, 0), (3, 4, 3), (8, 9, 12)]
Upvotes: 1
Reputation: 18
I think the easy way is to just iterate over the list and check whether you can find the same numbers or not.
for i in range(len(array)-1):
if array[i] == array[i+1]:
print(array[i]) // or add it to another list
Upvotes: 0