27. Problem to check whether a list contains a sublist or not.

In this program, we will take two lists as inputs and check whether the list contains a sublist with the help of the below-given steps.

List contains a sublist:

Steps to solve the program
  1. Take two lists as input.
  2. Check whether list2 is a sublist of list1 (i.e. all the elements from the list2 are in list1.
  3. Use for loop for this purpose.
  4. Print the output.
				
					#Input list
list1 = [22,45,67,12,78]

#Sublist
list2 = [45,12]

#Creating count variable
count = 0

for value in list1:
    for element in list2:
        if value == element:
            count += 1
            
#Printing output
if count == len(list2):
    print("Sublist exists")
else:
    print("Sublist does not exists")
				
			

Output :

				
					Sublist exists
				
			

Related Articles

Find the max, min, and sum of the list

Generate all sublists with 5 or more elements

26. Problem to find the max min and sum of the list.

In this program, we will take a user input as a list. Find the max min and sum of the list using in-built functions. Print the final output with the help of the below-given steps.

Max Min and Sum of the list elements:

Steps to solve the program
  1. Take a list as input.
  2. Find the minimum element from the list using min().
  3. Find the maximum element from the list using max().
  4. Find the sum of the list using sum().
  5. Print the output.
				
					#Input list
list1 = [22,66,89,9,44]

#Printing output
print("Minimum: ", min(list1))
print("Maximum: ", max(list1))
print("Sum: ", sum(list1))
				
			

Output :

				
					Minimum:  9
Maximum:  89
Sum:  230
				
			

Related Articles

Remove data from the list using pop method

Check whether a list contains a sublist

25. Problem to remove element from the list using pop method.

In this program, we will take a user input as a list. Remove the from the list from a specific index using pop method. Print the final output with the help of the below-given steps.

Remove element from the list using pop method:

Steps to solve the program
  1. Take a list as input.
  2. Remove an element whose index is 2 using pop method.
  3. Print the output.
				
					#Input list
list1 = [33,56,89,12,45]

#Removing elements which is at
#2nd index and printing output
list1.pop(2)
				
			

Output :

				
					[33, 56, 12, 45]
				
			

Related Articles

Sort a list using the sort and sorted method

Find the max, min, and sum of the list

24. Problem to sort a list using the sort and sorted method.

In this program, we will take a user input as a list. Sort the given list using the sort and sorted method with the help of the below-given steps.

Table of Contents

Sort and sorted method:

Method 1 : Using Sort()

Steps to solve the program
  1. Take a list as input.
  2. Sort the list using sort().
  3. Print the output.
				
					#Input list
list1 = [23,11,78,45,33]

#Using sort
list1.sort()
print("By sort function: ",list1)
				
			

Output :

				
					By sort function:  [11, 23, 33, 45, 78]

				
			

Method 2 : Using sorted()

Steps to solve the program
  1. Take a list as input,
  2. Sort the list using sorted().
  3. Print the output.
				
					#Input list
list1 = [23,11,78,45,33]

#using sorted
print("By sorted method: ",sorted(list1))
				
			

Output :

				
					By sorted method:  [11, 23, 33, 45, 78]
				
			

Related Articles

Add two lists using extend method

Remove data from the list using pop method

23. Problem to add two lists using extend method.

In this program, we will take two lists as inputs and combine them to make a single list using extend method with the help of the below-given steps.

Add lists using extend method:

Steps to solve the program
  1. Take two lists as input.
  2. Add them using extend().
  3. Print the output.
				
					#Input lists
list1 = [2,4,6,8,1]
list2 = [23,56,11,89]

#Combining lists
list1.extend(list2)

#Printing output
print(list1)
				
			

Output :

				
					[2, 4, 6, 8, 1, 23, 56, 11, 89]
				
			

Related Articles

List of words which has vowels in string

Sort a list using the sort and sorted method

22. Problem to get a list of words which has vowels in string.

In this program, we will take a user input as a string and convert it into a list. To check for words that have vowels in string with the help of the below-given steps.

Words which has vowels in string:

Steps to solve the program
  1. Take a string as input.
  2. Split the given string using split() and create an empty list.
  3. Using for loop and if statement check whether a word in the splitter string contains any vowels.
  4. If it has any vowels then add that word to the empty list.
  5. Print the list to see the words which has vowels in string.
				
					#Input string
string = "www Student ppp are qqqq learning Python vvv"

#Splitting a atring
string2 = string.split()

#Creating an empty list
list1 = []

for words in string2:
    for char in words:
    #Checking for vowels
        if char == "a" or char == "e" or char == "i"
        or char == "o" or char == "u":
            list1.append(words)
            break
            
#Printing output 
print(list1)
				
			

Output :

				
					['Student', 'are', 'learning', 'Python']
				
			

Related Articles

Check whether the list is palindrome or not

Add two lists using extend method

21. Problem to check whether the list is palindrome or not.

In this program, we will take a user input as a list and check whether the given list is palindrome or not with the help of the below-given steps.

List is palindrome:

Steps to solve the program
  1. Take a list as input.
  2. Create a variable and assign its value equal to the original list in reverse order.
  3. If both lists are equal then the list is a palindrome, else not.
				
					#Input list
list1 = [2,4,6,6,4,2]

#Creating variable and assign 
# value to it
list2 = list1[::-1]

#Printing output
if list1 == list2:
    print("List is palindrome")
else:
    print("List is not palindrome")
				
			

Output :

				
					List is palindrome
				
			

Related Articles

List of elements divided by a number

List of words which has vowels in string

20. Problem to get a list of elements divided by a number

In this program, we will take a user input as a list & iterate all the elements one by one with the python loop. Print the list of elements divided by a number with the help of the below-given steps.

Elements divided by number:

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Using for loop and if statement check whether an element from the given list is divisible by 3 or 7.
  3. Add only those elements to the empty list to get the list of elements divided by number.
  4. Print the list to see the output.
				
					#Input list
list1 = [3,7,0,2,6,14,88,21]

#Creating empty list
list2 = []

for value in list1:
#Checking whether the value is 
#divided by either 3 or 7
    if value%3 == 0 or value%7 == 0:
        list2.append(value)

#Printing output
print(value)
				
			

Output :

				
					[3, 7, 0, 6, 14, 21]
				
			

Related Articles

Remove negative elements from the list

Check whether the list is palindrome or not

19. Problem to remove negative elements from the list

We will take a user input as a list & iterate all the values one by one with the python loop to remove negative elements from it. Print only positive values with the help of the below-given steps.

Remove negative elements from list:

Steps to solve the program
  1. Take a list as input.
  2. Using for loop and if statement check whether an element from the given list is negative or positive.
  3. Print only positive elements.
				
					#Input list
list1 = [3,5,-8,0,-20,-55]

#Checking for positive values
for value in list1:
    if value >= 0:
        #Printing output
        print(value,end=" ")
				
			

Output :

				
					3 5 0
				
			

Related Articles

removing certain elements a list

List of elements divided by a number

18. Problem to print list after removing certain elements.

In this program, we will take a user input as a list & iterate all the values one by one with the python loop. Print the list after removing certain elements with the help of the below-given steps.

Removing certain elements from list:

Steps to solve the program
  1. Take a list as input.
  2. Using list comprehension, if statement and enumerate() remove certain elements from the list.
  3. Print the list after removing the elements.
				
					#Input list
list1 = [3,4,8,7,0,1,6,9]

list1 = [element for (value,element) in enumerate(list1) 
    if value not in (1,3,6)]

#Printing output
print(list1)
				
			

Output :

				
					[3, 8, 0, 1, 9]
				
			

Related Articles

common elements between lists

Remove negative elements