(5 points)
There are many possible ways to do this.
items.count can be used to check whether something
has two or more occurrences.
The challenge is to avoid printing such an item more
than once. One approach would be to keep an auxiliary list to
record
the items that have already been printed. This code might be
written as
printed = [] # empty list originally
for obj in items:
if items.count(obj) > 1 and obj not in printed:
print obj
printed.append(obj)
An alternative is to make sure to only print out the leftmost
occurrence of each element. This can be checked by using the
items.index method, yet to do this, we must
formulate our
loop over the integer indices rather than over the objects
themselves.
for i in range(len(items)):
if items.count(items[i]) > 1 and items.index(items[i]) == i:
print items[i]