Software engineering and personal development

Month: October 2022

How to Quickly Build Your Own Iterators in Python

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.

Continue reading

How to Quickly Avoid Errors when Getting Nonexisting Dictionary Elements

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:

 my_dictonary = {"name": "Name", "surname": "Surname"}
 print(my_dictonary["age"])  
Continue reading

© 2024 Fatos Morina

Theme by Anders NorenUp ↑