I am very beginner with Python and am having trouble with a certain aspect of the counter as it relates to its use in a nested for loop.
I am trying to run a nested for loop that checks if an array A has any duplicate values.
Trying to talk myself (and y'all) through this to make sense out of it: I am using a nested for loop to essentially loop through each item in array A...and for each item in array A, I need another counter to loop A so that I can compare A to itself in the form of counter i and counter j. Here is the issue: I don't want to count on itself aka i don't want to double count. And if I simply type the code that y'all will see below, it will double count (count on itself). So I want to make sure that the index of my inner for loop's counter is always +1 to my outer for loops counter.
Here is what the code looks like:
A = [4, 3, 2, 4]
for i in A:
for j in A:
if i == j:
print("yup")
the output is...you guessed it:
yup
yup
yup
yup
yup
yup
6 "yup"'s because each time it is counting each number on itself.
Hopefully I am explaining that properly...
So my question is: does anybody know how to make sure that my "j" counter is indexed +1...
I thought it would be:
for i in A:
for j = i + 1 in A:
if i == j:
print("yup")
but apparently that isn't right
Any insight here is very much appreciated!!!
Thanks, Mark