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 expression calculates the position of the alphabet by subtracting 96 from its Unicode code point. Since lowercase 'a' has a Unicode code point of 97, subtracting 96 gives 1, which represents the position of 'a'. Similarly, 'b' would be 2, 'c' would be 3, and so forth.
can someone explain me why -96 please?
This comment is hidden because it contains spoiler information about the solution
cool, why did I even bother with recursion
Pretty cool!
This comment is hidden because it contains spoiler information about the solution
.format() is older as it was introduced in python 2.6 while f-string is newer and from python 3.6
F-strings are generally more compact than .format() and easier to decipher but the biggest difference is in the ability for expressions within the f-string to be performed at runtime. This allows for things such as calling functions, creating classes, and math operations.
Additionally, f-strings are faster than .format()
What's the difference between .format() and a f-string?
the direction was to write the factorial function not to import the existing one
exactly what I thought.
maths...
nice
In isolation using
96
is fine, but structuring it the way Kosmarik proposed is more extensible in the future (for example, if you wanted to extend the function to return a character's position relative to any other character, it'd be easier to implement that by just replacing'a'
with a function argument).why would it be better? Every dev knows the ascii table and where to look it up in seconds and everyone who reads the solution instantly knows why to subtract exactly 96.
Your solution is much worse to read
You can do alphabet.lower()
Loading more items...