Question #103353

How can I check if there are any unique items in a list

Expert's answer

a=[1, 2, 3, 4, 4, 4, 5, 6, 5, 6]

c=0

for i in range(len(a)):

if a.count(a[i]) == 1:

print('YES', a[i])

c=1

if c == 0:

print('NO')


For example, we have list of digits 1, 2, 3, 4, 4, 4, 5, 6, 5, 6 and c=0

In the loop we check the count of each digit in the list. If it is unique, program output 'YES' and unique digit than c become equal 1. But if there are not unique objects, program output 'NO'


LATEST TUTORIALS
APPROVED BY CLIENTS