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?
exactly what I thought.
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()
doesn't work for uppercase.
Glad someone else had the same idea
Better than mine.
The second pop is redundant. We only need the min value in numbers, we don't need to pop it.
Well, it makes a change in the original list so it doesn't answer the problem.
thanks for your reply. if the problem was big then I would make a copy. for a simple problem like this i think it is ok. But copying list is always a good practice.
Using index method is a great idea! Thanks for inspiring me. Maybe you could make a Copy of the array,leaving the array unchanged.