Software engineering and personal development

Tag: lists

How Non-Empty Lists, Tuples, and Dictionaries are Evaluated to True

When working with conditional statements in Python, it’s important to understand how different data types are evaluated to True or False. In addition to the previously discussed false values such as None, "False", and 0, there are also some specific rules for evaluating lists, tuples, and dictionaries.

In Python, any non-empty list, tuple, or dictionary is evaluated to True, while an empty one is evaluated to False. This means that if you have a list or dictionary that contains at least one element, it will evaluate to True in a conditional statement.

Continue reading

How to Quickly Convert Tuples into Lists in Python

In Python, tuples and lists are two commonly used data structures for storing collections of items.

The main difference between them is that tuples are immutable, meaning their elements cannot be changed after they are created, while lists are mutable, meaning their elements can be modified.

This immutability of tuples makes them more memory efficient and faster than lists since they can be used as keys in a dictionary and in sets.

Continue reading

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

© 2024 Fatos Morina

Theme by Anders NorenUp ↑