Skip to content

Python slicing extracts a portion of a sequence using sequence[start:stop:step]. The stop position is excluded, and the step must not be zero. This tutorial explains forward and reverse slices with practical examples. Syntax start – Starting integer where the slicing of the object starts. Default to None if not provided.  stop — Exclusive bound. For a positive step, the last included position is before stop; with negative steps, indices decrease and the stop… Read More »Python List Slicing Explained: start, stop, step and Examples

Python List Slicing Explained: start, stop, step and Examples

Use list.index(value) to find the position of the first matching element in a Python list. Positions start at zero. This tutorial explains optional search bounds, duplicate values, missing items and alternatives for finding every match. Python list.index() syntax value is the item to find. The optional start index is inclusive; stop is exclusive. Both bounds follow slice-style indexing, including negative positions. The result is always an index in the original… Read More »Python list.index(): Find an Item’s Position and Handle ValueError

Python list.index(): Find an Item’s Position and Handle ValueError

Quick answer: To type a stacked fraction in Microsoft Word, choose Insert → Equation → Fraction, select a layout, and fill in the numerator and denominator. On desktop Word for Windows, Alt+= inserts an equation quickly. For simple symbols such as ½ or ¾, you can also use Insert → Symbol. Insert a stacked fraction using the Equation ribbon A built-up equation remains editable, unlike a precomposed fraction character. The… Read More »How to Type Fractions in Word: Equation Editor and Keyboard Shortcuts

How to Type Fractions in Word: Equation Editor and Keyboard Shortcuts

A Python list comprehension builds a new list by evaluating an expression for each item in an iterable, optionally filtering items with an if condition. It is useful for readable transformations, but not every loop should be compressed into one line. What is List Comprehension? List comprehension is a tool for creating a list from other list or sequence. Elements can be conditionally included in the new list and each element… Read More »Python List Comprehension: Syntax, Filtering and Examples

Python List Comprehension: Syntax, Filtering and Examples

Kadane’s algorithm finds the maximum sum of a contiguous, nonempty subarray in O(n) time and O(1) extra space. The key is to decide at each element whether to extend the current subarray or start a new one. For example, for an array, a = [-2, -4, 4, -2, -1, 1, 5, -7] A contiguous subarray = [4, -2, -1, 1, 5] gives the maximum sum of 7. Application Maximum sum… Read More »Kadane’s Algorithm: Maximum Subarray Sum in Python, Java and C++

Kadane’s Algorithm: Maximum Subarray Sum in Python, Java and C++

Python lists have three frequently confused methods for adding items: append() adds one object at the end, extend() adds each element from an iterable, and insert() places one object at a selected index. Following image summarizes all the three methods and what they do. Append() Method The append() method adds exactly one object to the end of the existing list, even when that object is another list. It always adds… Read More »Python append() vs extend() vs insert(): Differences with Examples

Python append() vs extend() vs insert(): Differences with Examples

Python’s list.insert(index, value) adds one object before a specified position in an existing list. Learn how zero-based indexes, negative indexes and out-of-range positions behave, with practical examples. Python list.insert() syntax list.insert(index, element) Parameters and return value This method takes two parameters: index where an element needs to be inserted element is the element to be inserted in the list. The method mutates the existing list and returns None. It inserts… Read More »Python list.insert(): Syntax, Examples, Index Rules and Pitfalls

Python list.insert(): Syntax, Examples, Index Rules and Pitfalls

Use Python’s list.extend(iterable) to append each item from another iterable to an existing list. Unlike append(), extend() adds the iterable’s elements individually and returns None. Syntax of Extend Method list1.extend(list2) Above code adds all the elements of list2 at the end of list1. It takes one iterable argument and adds each of its items individually to the existing list. Tuples, sets, strings and generators can be passed directly to extend().… Read More »Python list.extend(): Add Multiple Items from an Iterable

Python list.extend(): Add Multiple Items from an Iterable