Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
There are also subtractions. In fact, there is one more addition than subtractions.
If this kata is to be an exercise in regular expressions, its description should be updated to indicate that it is not looking for the actual domain in the URL, only a kind of approximation to it.
Because practically every solution that is currently accepted is incorrect--when using a more accurate definition of "domain".
For example, most solutions seem to hardcode "www." as being the only possible (optional) sub-domain. So that given the URL "subdomain.domain.tld", many solutions would return "subdomain" as the domain. And given the URL "nested.subdomain.domain.co.uk", many solutions would return "nested" as the domain.
I scrolled through a few ~pages of solutions, and not one of them would be able to accurately return the domain in those cases. Even the solution I submitted is not complete.
I understand the intent of the kata as an exercise for regular expressions, but it should be updated to reflect the fact that isn't actually looking for a proper domain (unless my definition of domain is different from everyone else's).
Note this won't work if
obj
is an instance of a subclass ofstr
: in such a case, the 'if' statement would be false and so the obj would returned as a list. Usingif isinstance(obj, str)
would resolve that.This will raise a ValueError if there's more than 1 ':' in a str "part".
a, *b = i.split(':')
would correct it.
This fails when
code
(num
) is0
: it raises a ValueError.The non-regex solution fails when
code
is0
: it raises a ValueError.This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This version is a bit more concise and easier to follow than my previous submission.
The main.py file (which contains content I did not create--I assume it executes the code that's submitted) contains a call to xrange(). This causes an error when using Python 3, as xrange() is no longer built-in. Submitting code against Python 2 works, however (since xrange() is built-in for Python 2).