30. Problem to find the second smallest number from the list.

In this program, we will take a user input as a list. Find the second smallest number from the list with the help of the below-given steps.

Second smallest number in a list:

Steps to solve the program
  1. Take a list as input.
  2. Sort the list using sort().
  3. Print the second smallest number from the list using indexing.
				
					#Input list
list1 = [22,11,78,45,90,44]

#Sorting the list
list1.sort()

#Printing output
print("2nd smallest number: ", list1[1])
				
			

Output :

				
					2nd smallest number:  22
				
			

Related Articles

Find the second largest number from the list

Merge all elements using special character

29. Problem to find the second largest number in the list.  

In this program, we will take a user input as a list. Find the second largest number from the list with the help of the below-given steps.

Second largest number in a list:

Steps to solve the program
  1. Take a list as input.
  2. Sort the list using sort().
  3. Print the second largest number from the list using indexing.
				
					#Input list
list1 = [22,11,78,45,90,44]

#sorting the list
list1.sort()

#printing the output
print("2nd largest number: ", list1[-2])
				
			

Output :

				
					2nd largest number:  78
				
			

Related Articles

Generate all sublists with 5 or more elements

Find the second smallest number from the list

28. Problem to generate all sublists with 5 or more elements.

In this program, we will take a user input as a list. Generate all sublists having 5 or more elements in it from the given list with the help of the below-given steps.

Generate all sublists of a list:

Steps to solve the program
  1. Take a list as input and create an empty list to store and generate all sublists.
  2. From itertools import combinations for generating sublists with 5 or more elements.
  3. Use for loop and range function for this purpose.
  4. If the generated list contains 5 or more elements add that list as a sublist to the empty list.
  5. Print the list to see the output.
				
					#Importing combinations
from itertools import combinations

#Input list
list1 = [1,3,5,8,0,22,45]

#Creating an empty list
sub = []

for i in range(0,len(list1)+1):
#Checking for combinations
    for sublist in combinations(list1,i):
        temp = list(sublist)
        if len(temp) > 4:
            sub.append(temp)

#Printing output
print(sub)
				
			

Output :

				
					[[1, 3, 5, 8, 0],
 [1, 3, 5, 8, 22],
 [1, 3, 5, 8, 45],
 [1, 3, 5, 0, 22],
 [1, 3, 5, 0, 45],
 [1, 3, 5, 22, 45],
 [1, 3, 8, 0, 22],
 [1, 3, 8, 0, 45],
 [1, 3, 8, 22, 45],
 [1, 3, 0, 22, 45],
 [1, 5, 8, 0, 22],
 [1, 5, 8, 0, 45],
 [1, 5, 8, 22, 45],
 [1, 5, 0, 22, 45],
 [1, 8, 0, 22, 45],
 [3, 5, 8, 0, 22],
 [3, 5, 8, 0, 45],
 [3, 5, 8, 22, 45],
 [3, 5, 0, 22, 45],
 [3, 8, 0, 22, 45],
 [5, 8, 0, 22, 45],
 [1, 3, 5, 8, 0, 22],
 [1, 3, 5, 8, 0, 45],
 [1, 3, 5, 8, 22, 45],
 [1, 3, 5, 0, 22, 45],
 [1, 3, 8, 0, 22, 45],
 [1, 5, 8, 0, 22, 45],
 [3, 5, 8, 0, 22, 45],
 [1, 3, 5, 8, 0, 22, 45]]
				
			

Related Articles

Check whether a list contains a sublist

Find the second largest number from the list

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