Python List of Lists – A Helpful Illustrated Guide to Nested Lists in Python

There’s an element of confusion regarding the term “lists of lists” in Python. I wrote this most comprehensive tutorial on list of lists in the world to remove all those confusions by beginners in the Python programming language. This multi-modal tutorial consists of: Source code to copy&paste in your own projects. Interactive code you can … Read more

Python List to Tuple

Problem: Given a Python list with n elements. How to convert it into a tuple with the same n elements? Examples: Note Tuple: Tuples are similar to lists—with the difference that you cannot change the tuple values (tuples are immutable) and you use parentheses rather than square brackets. Solution: Use the built-in Python tuple() function … Read more

Python sum() List – A Simple Illustrated Guide

Summing up a list of numbers appears everywhere in coding. Fortunately, Python provides the built-in sum() function to sum over all elements in a Python list—or any other iterable for that matter. (Official Docs) The syntax is sum(iterable, start=0): Argument Description iterable Sum over all elements in the iterable. This can be a list, a … Read more

How to Remove Duplicates From a Python List?

Do you know the best way of removing duplicates from a Python list? This is a popular coding interview question at Google, Facebook, and Amazon. In this article, I’ll show you how (and why) it works—so keep reading! How to remove all duplicates of a given value in the list? Naive Method: Go over each … Read more