51. Problem to create a list of lists whose sum of elements is highest.

In this Python list program, we will take a user input as a list and find the list in a list of lists whose sum of elements is the highest with the help of the below-given steps.

List of lists having sum of list elements:

Steps to solve the program
  1. Take user input as a list of lists.
  2. Use the built-in max() function and set key=sum to get the list having the maximum sum of elements.
  3. Print that list.
				
					#Input list
list1 = [[11, 2, 3], [4, 15, 2], [10, 11, 12], [7, 8, 19]]

#Printing output
print(max(list1,key=sum))
				
			

Output :

				
					[7, 8, 19]
				
			

Related Articles

Move all zero digits to the end

Items that start with a specific character

50. Problem to move all zero digits to the end.

In this program, we will take a user input as a list and move all zero digits to the end of a given list of numbers with the help of the below-given steps.

Move all zero digits to the end:

Steps to solve the program
  1. Take a list as input.
  2. Create a variable var and assign its value equal to 0.
  3. Use for loop with the range function to iterate over elements in the list.
  4. If the iterated element is greater than 0 then assign its value to the temp variable.
  5. Assign the value of that index number equal to list1[var]
  6. Now change the value of list1[var] to temp variable.
  7. Add 1 to the var variable.
  8. Print the output to see the result i.e. move all zero digits to the end.
				
					#Input list
list1 = [3, 4, 0, 0, 0, 0, 6, 0, 4, 0, 22, 0, 0, 3, 21, 0]
var = 0

for i in range(0,len(list1)) :
    if (list1[i] > 0) :
        temp = list1[i]
        list1[i] = list1[var]
        list1[var]= temp
        var += 1

#Printing output
print(list1)
				
			

Output :

				
					[3, 4, 6, 4, 22, 3, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0]
				
			

Related Articles

Move all positive numbers on the left

List of lists whose sum of elements is highest

49. Problem to move all positive numbers on the left

In this Python list program, we will take a user input as a list and move all positive numbers to the left side and negative numbers to the right side with the help of the below-given steps.

Move all positive numbers in a list:

Steps to solve the program
  1. Take a list as input.
  2. Create a variable var and assign its value equal to 0.
  3. Use for loop with the range function to iterate over elements in the list.
  4. If the iterated element is greater than 0 then assign its value to the temp variable.
  5. Assign the value of that index number equal to list1[var]
  6. Now change the value of list1[var] to temp variable.
  7. Add 1 to the var variable.
  8. Print the output to see the result i.e. move all positive numbers to the left.
				
					#Input list
list1 = [2, -4, 6, 44, -7, 8, -1, -10]
var = 0

#Sorting list
for i in range(0,len(list1)) :
    if (list1[i] > 0) :
        temp = list1[i]
        list1[i] = list1[var]
        list1[var]= temp
        var += 1

#Printing output        
print(list1)
				
			

Output :

				
					[2, 6, 44, 8, -7, -4, -1, -10]
				
			

Related Articles

Iterate over lists and create a list of sublists

Move all zero digits to the end

48. Problem to create a list of sublists.

In this Python list program, we will take two lists as input and iterate over lists to create a list of sublists with the help of the below-given steps.

Create a list of sublists:

Steps to solve the program
  1. Take two lists as inputs.
  2. Create an empty list to store a list of sublists.
  3. Use for loop and zip function to combine the input lists and add them to the empty list.
  4. Print the list to see the output.
				
					#Input lists
list1 = [1, 3, 5, 7, 9]
list2 = [8, 6, 4, 2, 10]

#Creating empty list
empty_list = []
for (a,b) in zip(list1,list2):
    elements = [a, b]
    empty_list.append(elements)

#printing output    
empty_list
				
			

Output :

				
					[[1, 8], [3, 6], [5, 4], [7, 2], [9, 10]]
				
			

Related Articles

Insert a given string at the beginning

Move all positive numbers on the left

47. Problem to insert a given string at the beginning of list elements.

In this Python list program, we will take a user input as a list and insert the given string at the beginning of the list elements with the help of the below-given steps.

Insert a string at the beginning of list elements:

Steps to solve the program
  1. Take a list as input.
  2. Add ‘sqa’ at the beginning of every element of the list.
  3. Use the list comprehension method for this purpose.
  4. Use for loop to iterate over elements in the list.
  5. During the loop add ‘Sqa’ to each element using the .format() method.
  6. Print the output to see the result.
				
					#Input list
list1 = [1, 2, 3, 4, 5]

#Printing output
print(['Sqa{0}'.format(value) for value in  list1])
				
			

Output :

				
					['Sqa1', 'Sqa2', 'Sqa3', 'Sqa4', 'Sqa5']
				
			

Related Articles

Create a list of five consecutive numbers

Iterate over lists and create a list of sublists

46. Problem to create a list of five consecutive numbers.

In this Python list program, we will create a list of five consecutive numbers with the help of the below-given steps.

List of five consecutive numbers:

Steps to solve the program
  1. Create a list and use the list comprehension method.
  2. With the help of the range function create a list of five consecutive numbers.
  3. Print the output to see the result.
				
					#Input list
list1 = [[5*i + j for j in range(1,6)] for i in range(4)]

#Printing output
print(list1)
				
			

Output :

				
					[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], 
[11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]
				
			

Related Articles

Create a sublist of numbers and their squares

Insert a given string at the beginning

45. Problem to create a sublist of numbers and their squares

In this Python list program, we will create a sublist of numbers and their squares with the help of the below-given steps.

Create a sublist of numbers:

Steps to solve the program
  1. Create a list and use the list comprehension method.
  2. With the help of range, function create a sublist of numbers and their squares.
  3. Print the list to see the output.
				
					#Input list
list1 = [[i,i**2] for i in range(1,11)]

#Printing output
print(list1)
				
			

Output :

				
					[[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], 
[6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]
				
			

Related Articles

Print list elements separately

Create a list of five consecutive numbers

44. Problem to print list elements separately.

In this Python list program, we will take a user input as a list and print list elements separately with the help of the below-given steps.

Print list elements separately:

Steps to solve the program
  1. Take a list as input.
  2. Use for loop to print the elements separately.
  3. Print the output to see the result.
				
					#Input list
list1 = [("Black", "Yellow", "Blue"), (50, 55, 60), (30.0, 50.5, 55.66)]

for value in list1:
    print(value)
				
			

Output :

				
					('Black', 'Yellow', 'Blue')
(50, 55, 60)
(30.0, 50.5, 55.66)
				
			

Related Articles

Convert a list of words into a single string

Create a sublist of numbers and their squares

43. Problem to convert a list of words into a single string.

In this Python list program, we will take a user input as a list and containing words and convert a list of words into a single string with the help of the below-given steps.

Convert a list of words to a string:

  1. Take a list containing words as Input.
  2. Use for loop to combine the words.
  3. Print the output.
				
					#Input list
list1 = ["Sqa", "Tools","Best", "Learning", "Platform"]

for word in list1:
    print(word, end="")
				
			

Output :

				
					SqaToolsBestLearningPlatform
				
			

Related Articles

Convert multiple numbers into a single number

Print list elements separately

42. Problem to convert multiple numbers into a single number.

In this Python list program, we will take a user input as a list and convert multiple numbers from that list into a single number with the help of the below-given steps.

Convert multiple numbers to a single number:

Steps to solve the program
  1. Take user input as a list.
  2. Use for loop to combine multiple numbers into a single number.
  3. Print the output.
				
					#Input list
list1 = [12, 45, 56]

for value in list1:
    print(value, end="")
				
			

Output :

				
					124556
				
			

Related Articles

common member in lists

Convert a list of words into a single string