• 21 December

    Python count items in the list

    In this tutorial, we will see how to count items inlist in python Count total items in the list You can use len() function to count items in the list. Let’s understand with the help of example. [crayon-607ca567ca8a2691177405/] Output: List: [1, 2, 3, 4] Length of list1: 4 Count occurence of each element in the […]

  • 19 December

    Python list to tuple

    In this tutorial, we will see how to convert list to tuple. Using tuple function You can use python tuple() function to convert list to tuole.It is simplest way to convert list to tuple. Let’s understand with the help of example. [crayon-607ca567cb135872474875/] Output: List of Fruits [‘Apple’, ‘Orange’, ‘Grapes’, ‘Banana’] Tuple of Fruits: (‘Apple’, ‘Orange’, […]

  • 10 October

    Convert string to list python

    In this post, we will see how to convert String to list in Python. We can use String’s split function to convert String to list. String’s split function Python String split function signature [crayon-607ca567cb4cf149191218/] Parameters sep: A string parameter that will be used as a separator. maxsplit: Number of times split Let’s see some examples. […]

  • 08 October

    Remove last element from list python

    In this post, we will see how to remove the last element from a list in python. Using list.pop() You can use list.pop() method to remove the last element from the list. [crayon-607ca567cb837193558421/] Output: List Of Countries are: [‘India’, ‘China’, ‘Bhutan’, ‘Nepal’] List Of Countries after removing last element: [‘India’, ‘China’, ‘Bhutan’] Removed country: Nepal […]

  • 01 April

    python convert list to string

    In this post, we will see how to convert a list to String in Python. You can simply use string’s join method to convert a list to String in Python. String’s join method string’s join method return string in which element of the sequence is joined by separator. [crayon-607ca567cbbb5582355544/] Let’s see some examples. Join all […]

  • 01 April

    Remove from list Python

    In this post, we will see how to remove an element from list in python. You can remove elements from list in 3 ways. Using list object’s remove method Here you need to specify element which you want to remove. If there are multiple occurrences of element, then first occurrence will be removed. Please note […]

  • 23 December

    Python sort list of tuples

    In this tutorial, we will see about how to sort list of tuples on the basis of various criterion. Let’s understand with the help of example Let’s say you have list of tuples as below: [crayon-607ca567cc385569231724/] Now you want to sort list of tuples based on age and age is 1st index in tuple. You […]

  • 08 December

    Python Convert list to set

    In this tutorial, we will see how to convert list to set. You can use python set() function to convert list to set.It is simplest way to convert list to set. As Set does not allow duplicates, when you convert list to set, all duplicates will be removed in the set. Let’s understand with the […]

  • 08 December

    How to create an empty list in python

    In this post, we will see how to create an empty list in python. There are two ways to create an empty list in Python. Using [ ] Using list() function. Let’s see this with the help of example. list1=[] list1.append(1) list1.append(2) list2=list() list2.append(1) list2.append(2) print("List 1:",list1) print("List 2:",list2) [/datacamp_sample_code] [/datacamp_exercise] Output: List 1: [1, […]