Q:

I want to create a program that returns a list that contains only the elements that are common between the lists (without duplicates)

Below is the code:
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c = []

cal = len(a)

for d in range(cal):
     if a[d] in b and a[d] not in c:
         c.append(a[d])
print(c)

Below is the output:
[1, 2, 3, 5, 8, 13]
Process finished with exit code 0
I was not able to make the logic myself so I had looked at the solution but still didn't get the concept behind the code. The point where I am getting confused is that in cal I am storing the length of a which is 11, then I am doing a for loop 11 times(I am not sure why this is being done and what will we get from this part), then then finally conditional using "a[d]". It just doesnt makes sense to me.

A:

let's break done the code
range(integer_value)

Returns a list of elements from 0 to integer_value -1 that's why you can iter over it
with this said:
#this is returning the longitude of the list
cal = len(a) 
#this is iterating over a list of [0,1,2,3... until len -1)
for d in range(cal):
    #this checks if the value of a in the position d is in the list called b
    #this is also checking that it's not in c to avoid duplication,
    #but you could use a set which is a "list" that doesn't accept duplicates
    if a[d] in b and a[d] not in c:
         c.append(a[d])

