I've gotten a lot of tests (but not all) to pass but in trying to be more elegant, I kinda restarted. At the minute I have this code:
def is_valid(isbn):
isbn_list = list(isbn)
digits = ['0','1','2','3','4','5','6','7','8','9','X']
for index, item in enumerate(isbn_list):
if item not in digits:
isbn_list.pop(index)
return isbn_list
and for example on test 5 it is giving the error:
Code Run
self.assertIs(is_valid("4-598-21507-B"), False)
Test Failure
AssertionError: ['4', '5', '9', '8', '2', '1', '5', '0', '7', 'B'] is not False
I have it returning the list for the moment just so I can see what is happening and make sure the data I'll process is cleaned. I don't understand why it's successfully removing the dashes, but then allows 'B' through? It also allows through other non-X letters in other tests...