write a function that takes, as an argument, a list called aList. It returns a Boolean True if the list contains each of the integers between 1 and 6 exactly once, and False otherwise.
This is homework and I thought I had it right, but it is now telling me that it isn't right. Here is my code.
count = 0
for i in set(aList):
count += 1
return aList.count(i) == 1
return inside the loop, you are only checking one value. You need to check each value. Also, instead of looping through the items of the list, you should loop through the items you're actually looking for. It would also help to make sure there are the correct number of items in the list.
def isItAStraight(aList): if len(aList) != 6: return False for i in range(1, 7): if aList.count(i) != 1: return False return True
But the easiest way to do this is to simply sort the list and check if it's what you're looking for:
def isItAStraight(aList): return sorted(aList) == list(range(1, 7))