Software engineering and personal development

Tag: element (Page 2 of 2)

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

How to Quickly Find the Largest and Smallest Element in a List in Python

eyeglasses with black frames on white desk
Photo by Temple Cerulean on Unsplash

One 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 reading

How to Remove Duplicate Elements in a List in Python

MacBook Pro, white ceramic mug,and black smartphone on table
Photo by Andrew Neel on Unsplash

Lists are part of typically every project that you work on these days. You have lists of people, a list of products, a list of activities, and the list of lists goes on.

There can be times when you want to only have unique elements in that list, for example, if someone has liked multiple posts and you want to get all the people who have liked one of your posts. You do not want to include that same person multiple times in that list.

Continue reading
Newer posts »

© 2024 Fatos Morina

Theme by Anders NorenUp ↑