The Python Counter
class from the collections
module is a powerful tool that we can also use for counting the occurrences of elements in a list.
Tag: sort
One of the common things that you can notice in many tasks is the fact that you need to sort elements in a list. In fact, this can also be part of an interview that you may go through while applying for a job. Maybe not only sorting elements, but sorting elements fulfilling certain conditions.
Continue readingOne of the first algorithms that we are usually taught is finding either the smallest or the largest element in a list of elements by iterating through every element in a list.
Let’s assume that we are trying to find the smallest element in a list.
The algorithm is quite straightforward and intuitive even for a 5-year-old: You assume that the first element is the smallest and save its value in a variable.
Continue readingChecking whether a word is an anagram of another one can be a question that is quite common in coding interviews.
If you don’t know what an anagram is, here is a definition:
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word anagram itself can be rearranged into nag a ram, also the word binary into brainy and the word adobe into abode.
Continue reading