What’s the Double Colon :: Operator in Python?

Problem Formulation: What does the double colon string[::2] or sequence[3::4] mean in Python? >>> string[::2] You can observe a similar double colon :: for sequences: >>> lst = [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> lst[::2] Answer: The double colon is a special case in Python’s extended slicing feature. The extended slicing … Read more

Python reversed() — A Simple Guide with Video

Python’s built-in reversed(sequence) function returns a reverse iterator over the values of the given sequence such as a list, a tuple, or a string. Usage Learn by example! Here are some examples of how to use the reversed() built-in function. The most basic use is on a Python list: You can see that the return … Read more

Python set() Function — A Simple Guide with Video

Python’s built-in set() function creates and returns a new set object. A set is an unordered collection of unique elements. Without an argument, set() returns an empty set. With the optional argument, set(iter) initializes the new set with the elements in the iterable. Read more about sets in our full tutorial about Python Sets. Usage … Read more

Linked Lists in Python

In this blog post you will learn how to implement a linked list in Python from scratch. We will understand the internals of linked lists, the computational complexity of using a linked list and some advantages and disadvantages of using a linked list over an array. Introduction Linked list is one of the most fundamental … Read more

Python filter()

Python’s built-in filter() function is used to filter out elements that pass a filtering condition. It takes two arguments: function and iterable. The function assigns a Boolean value to each element in the iterable to check whether the element will pass the filter or not. It returns an iterator with the elements that pass the … Read more

Python len()

Python’s built-in function len() returns the length of the given string, array, list, tuple, dictionary, or any other iterable. The type of the return value is an integer that represents the number of elements in this iterable. Usage Learn by example! Here are some examples on how to use the len() built-in function. The examples … Read more