A leap year is a year that has 366 days instead of the usual 365. It occurs every four years and is the year when an extra day, February 29th, is added to the calendar. This day, known as a leap day, helps to keep the calendar aligned with the Earth’s movements around the sun. Leap years occur every four years, with the next one occurring in 2024.
We can check whether a year is a leap year in Python in a few ways.
If you want to delete every other element in a list in Python, you can do that fairly quickly.
Let us assume that we want to delete elements that are in positions 0, 2, 4, 6, meaning that we are starting from index 0 and we are adding 2 for every next element that we are deleting.
Anagrams are strings that have the same letters but in a different order for example abc, bca, cab, acb, bac are all anagrams, since they all contain the same letters.
We can check whether two strings are anagrams in Python in different ways. One way to do that would be to use Counter from the collections module.
A Counter is a dict subclass for counting hashable objects. It is a collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Counts are allowed to be any integer value including zero or negative counts. The Counter class is similar to bags or multisets in other languages.
In plain English, with Counter, we can get a dictionary that represents the frequency of elements in a list. Let us see this in an example:
You have probably had the chance to iterate through a list of elements in one way or another, or through elements of a set, or a dictionary. We can go through a list, a set, or a dictionary and access their elements because they are iterable objects.
An iterator is an object that contains a countable number of objects. This means that you can iterate through elements that an iterator contains.
Dictionaries also known as maps are data structures that are used a lot in different scenarios. The process of getting an element from a dictionary can be done using an element that is not part of the dictionary which results in an error.
For example, let us take this scenario where we have a dictionary that has an element with the key name and another one with the element surname. If we want to access it using another element, such as age, we are going to see an error like the following:
I am an experienced and passionate Senior Software Engineer with a demonstrated history of working in the full life cycle of software development with enormous curiosity for data science, machine learning, algorithms, data structures, and solving challenging problems. I am an open-source enthusiast at https://github.com/fatosmorina and also a writer.
I am open for new opportunities.