I want to know if a list contains only one element, without using len.
What is the most pythonic way to do it between these two solutions? Or maybe none of these are pythonic, and if so what is then?
Solution a: remove item at position 1 and except an IndexError so I know there was only 1 item.
try: a_list.pop(1): except IndexError: #blah solution b: use slicing to remove first element and check if the list is now empty
if not a_list[1:]: # blah
if len(a_list) != 1:if len(a_list) == 1