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

41. Problem to return true if one common member in lists else False.

In this program, we will take two lists as input & return true when there is at least one common member in lists with the help of the below-given steps.

Common member in lists:

Steps to solve the program

  1. Take use lists as inputs.
  2. Use for loop for checking common members in the list.
  3. Return true at least one common member in lists.
  4. Print the output to see the result.
				
					#Input list
list1 = [25,65,77,14,23,96]
list2 = [65,35,62,77]

#Creating result variable
result = False

for val in list1:
    for ele in list2:
        if ele == val:
            result = True
            print(f"{ele} exists in list2", result)
				
			

Output :

				
					65 exists in list2 True
77 exists in list2 True
				
			

Related Articles

Remove all odd index elements.

Convert multiple numbers into a single number

40. Problem to remove all odd index elements.

In this program, we will take a user input as a list and remove all odd index elements from that list with the help of the below-given steps.

Remove odd index elements from a list:

Steps to solve the program
  1. Take a list as input.
  2. Create an empty list.
  3. Use for loop with range function to remove all odd index elements.
  4. Add the remaining elements to the empty list.
  5. Print the output to see the result.
				
					Input list
list1 = [12, 32, 33, 5, 4, 7, 33]

#Creating an empty list
list2 = []

for i in range(len(a)):
    if i%2 == 0:
        list2.append(list1[i])

#printing output
print(list2)
				
			

Output :

				
					[12, 33, 4, 33]
				
			

Related Articles

Check the given element exists in the list

Return true if one common member in lists

39. Problem to check the given element exists in the list.

In this program, we will take a user input as a list and that if the given element exists in the list or not with the help of the below-given steps.

Element exists in the list:

Steps to solve the program
  1. Take a list as input.
  2. Use the membership operator i.e. in or not in to check whether an element exists in the list or not.
  3. Print the output to see the result.
				
					#Input list
list1 = [22,45,67,11,90,67]

#Printing output
print("Is 67 exsist in list1? ", 67 in list1)
print("Is 15 exsist in list1? ", 15 in list1)
				
			

Output :

				
					Is 67 exsist in list1?  True
Is 15 exsist in list1?  False
				
			

Related Articles

Replace the last and the first number of the list

Remove all odd index elements

38. Problem to replace the last and the first number of the list

In this program, we will take a user input as a list and replace the last and the first number of the list with the word with the help of the below-given steps.

Replace the last and the first number in a list:

Steps to solve the program
  1. Take a list as input.
  2. Replace the 1st element i.e. element with index value 0 with “SQA”.
  3. Replace the last element i.e. element with index value -1 in the reverse order with “TOOLS”.
  4. Print the list to see the output i.e. replace the last and the first number with a word.
				
					#Input list
list1 = [12, 32, 33, 5, 4, 7]

#Replacing first and last element
list1[0] = "SQA"
list1[-1] = "TOOLS"

#Printing output
print(list1)
				
			

Output :

				
					['SQA', 32, 33, 5, 4, 'TOOLS']
				
			

Related Articles

Get all the unique numbers in the list

Check the given element exists in the list