Category: Lists

  • List Exercises

    Python List Exercise 1 Python program to find unique numbers in a given list. L1 =[1,9,1,6,3,4,5,1,1,2,5,6,7,8,9,2] L2 =[]for x in L1:if x notin L2: L2.append(x)print(L2)</pre> It will produce the following output − [1, 9, 6, 3, 4, 5, 2, 7, 8]Python List Exercise 2Python program to find sum of all numbers in a list.L1 = [1, 9,…

  • List Methods

    List is one of the fundamental data structures in Python, It provides a flexible way to store and manage a collection of items. It has several built-in methods that allow you to add, update, and delete items efficiently. Lists in Python can contain items of different data types, including other lists, making them highly flexible…

  •  Join Lists

    Join Lists in Python Joining lists in Python refers to combining the elements of multiple lists into a single list. This can be achieved using various methods, such as concatenation, list comprehension, or using built-in functions like extend() or + operator. Joining lists does not modify the original lists but creates a new list containing the combined elements.…

  • Copy Lists

    Copying a List in Python Copying a list in Python refers to creating a new list that contains the same elements as the original list. There are different methods for copying a list, including, using slice notation, the list() function, and using the copy() method. Each method behaves differently in terms of whether it creates…

  •  Sort Lists

    Sorting Lists in Python Sorting a list in Python is a way to arrange the elements of the list in either ascending or descending order based on a defined criterion, such as numerical or lexicographical order. This can be achieved using the built-in sorted() function or by calling the sort() method on the list itself,…

  • List Comprehension

    List Comprehension in Python A list comprehension is a concise way to create lists. It is similar to set builder notation in mathematics. It is used to define a list based on an existing iterable object, such as a list, tuple, or string, and apply an expression to each element in the iterable. Syntax of Python List Comprehension The…

  • Loop Lists

    Loop Through List Items Looping through list items in Python refers to iterating over each element within a list. We do so to perform the desired operations on each item. These operations include list modification, conditional operations, string manipulation, data analysis, etc. Python provides various methods for looping through list items, with the most common being the for…

  •  Remove List Items

    Removing List Items Removing list items in Python implies deleting elements from an existing list. Lists are ordered collections of items, and sometimes you need to remove certain elements from them based on specific criteria or indices. When we remove list items, we are reducing the size of the list or eliminating specific elements. We…

  • Add List Items

    Add List Items Adding list items in Python implies inserting new elements into an existing list. Lists are mutable, meaning they can be modified after creation, allowing for the addition, removal, or modification of their elements. Adding items in a list typically refers to appending new elements to the end of the list, inserting them…

  •  Change List Items

    Change List Items List is a mutable data type in Python. It means, the contents of list can be modified in place, after the object is stored in the memory. You can assign a new value at a given index position in the list Syntax list1[i] = newvalue Example In the following code, we change the value at…