Bob Bob - 1 month ago 14
Python Question

How to check whether elements appears in the list only once in python?

I have a list:

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


Please, explain to me how to check whether element appears only once in in the list?

Please, also explain if all elements from 1 to
len(a)
are in the list. For instance, in list 'a' element from 1 to 7 are in the list, but if the list is
b = [1, 4, 3, 5]
, then not all elements from 1 to 4 are not in the list.

Thank you!

Answer
len( set( a ) ) == len( a )

for the first question, and

( len( set( a ) ) == len( a ) == max( a ) ) and min( a ) == 1

for the second.