by Suf | Jan 25, 2022 | Programming, Python, Tips
The length of a Python list is the same as the number of items in the list. You can find the length of a list using the built-in len() function. You can also use a for loop to iterate over the list and count the number of items. This tutorial will go through...
by Suf | Jan 24, 2022 | Programming, Python, Tips
The Cartesian product of two sets A and B denoted A x B is the set of all possible ordered pairs (a, b), where a is in A and b is in B. We can get the Cartesian product between two lists saved as a 2D list in Python. This tutorial will go through different methods to...
by Suf | Jan 23, 2022 | Programming, Python, Tips
The max() function is built into Python and returns the item with the highest value in an iterable or the item with the highest value from two or more objects of the same type. When you pass an iterable to the max() function, such as a list, it must have at least one...
by Suf | Jan 22, 2022 | Programming, Python, Tips
If you define an array and try to index it with more dimensions than the array has, you will raise the error: IndexError: too many indices for array. You need to recheck the array’s dimensions and index it with those dimensions to solve this error. This tutorial...
by Suf | Jan 22, 2022 | Programming, Python, Tips
When you want to access a value inside a list, you must use an index value in the range of the list. Using an index value out of range will raise the error: IndexError: list index out of range. You can solve this index error by using the range function on the length...
by Suf | Jan 21, 2022 | Programming, Python, Tips
This error occurs when you define a function with a non-default parameter following a default parameter. If positional parameters follow a default parameter, the Python interpreter cannot know if you passed an argument for the default parameter or for one of the...