There are multiple solutions, so you can pick your poison. Assuming a is a list of 100 Nones, here are some that I could think of (sorted by performance on my machine):
Using set:
def only_element(element, ls):
return set(ls) == set([element])
Timing:
$ python -m timeit 'set(a) == set([None])'
100000 loops, best of 5: 3.06 µs per loop
Using all:
def only_element(element, ls):
return all([item == element for item in ls])
Timing:
$ python -m timeit 'all([item == None for item in a])'
50000 loops, best of 5: 8.81 usec per loop
Using a for loop:
def only_element(element, ls):
for item in ls:
if item != element:
return False
return True
Timing:
$ python -m timeit 'for item in a:\n if item != None:\n break'
100000 loops, best of 5: 9.16 µs per loop
Using filter:
def only_element(element, ls):
return len(list(filter(lambda x: x != element, ls))) == 0
Timing:
$ python -m timeit 'len(list(filter(lambda x: x != None, a))) == 0'
10000 loops, best of 5: 20.8 usec per loop
What's the takeaway?
Usually, there's a built-in function that suits your needs better and runs faster (and with less code) than if you were to use a for loop.
filterNoneonly, how about justif None in mydict: ...?all(i is None for i in your_list)?