80. Problem to print palindrome numbers from a list.  

In this program, we will take a user input as a list and get palindrome numbers from a given list.

Palindrome numbers in a list:

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Calculate the reverse of each number from the given list using for and while loop.
  3. Check if the original number and reversed numbers are equal or not.
  4. if equal then add those reverse number to the empty list.
  5. Print the list to see the result.
				
					#Input list
list1 = [121, 134, 354, 383, 892, 232]
list2 = []

for value in list1:
    num = value
    reverse=0
    while num != 0:
        digit = num%10
        reverse = reverse*10 + digit
        num //= 10
    if reverse == value:
            list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					[121, 383, 232]
				
			

Related Articles

Reverse all the numbers in a given list

Count the total number of vowels in a list

79. Problem to reverse all the numbers in a given list.  

In this Python list program, we will take a user input as a list and reverse all the numbers in a given list with the help of the below-given steps.

Reverse all the numbers in a list:

Steps to solve the program
  1. Take a list as input and create an empty list.
  2. Calculate the reverse of each number from the given list using for and while loop.
  3. Add the reverse number to the empty list.
  4. Print the list to see the result.
				
					#Input lists
list1 = [123, 145, 633, 654, 254]
reverse_list = []

#Calculating reverse number
for value in list1:
    reverse = 0
    while value != 0:
        digit = value%10
        reverse = reverse*10 + digit
        value //= 10
    reverse_list.append(reverse)

#Printing output
print(reverse_list)
				
			

Output :

				
					[321, 541, 336, 456, 452]
				
			

Related Articles

Get a list of Fibonacci numbers from 1 to 20

Print palindrome numbers from a given list

78. Problem to get a list of Fibonacci numbers from 1 to 20.

In this Python list program, we will get a list of Fibonacci numbers from 1 to 20 with the help of the below-given steps.

List of fibonacci numbers:

Steps to solve the program
  1. Create an empty list.
  2. Calculate the Fibonacci series of numbers from 1 to 20 using for loop with the range function.
  3. Add that series to the empty list.
  4. Print the list to see the result.
				
					#Creating empty list
list1 = []

num1 = 0
num2 = 1

for i in range(1,21):
    list1.append(num1)
    n2 = num1+num2
    num1 = num2
    num2 = n2

#Printing output
print(list1)
				
			

Output :

				
					[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 
144, 233, 377, 610, 987, 1597, 2584, 4181]
				
			

Related Articles

Calculate the factorial of each item in the list

Reverse all the numbers in a given list

77. Problem to calculate the factorial of each item in the list.

In this Python list program, we will calculate the factorial of each item in the list with the help of the below-given steps.

Factorial of each item in list:

Steps to solve the program
  1. Take a list as input.
  2. Create a function for calculate factorial of a number.
  3. Create a new list and calculate the factorial of each number from the given list using list comprehension.
  4. Print the new list to see the output.
				
					#Creating function
def factorial(n):
    fact = 1
    
    for i in range(1, n + 1):
        fact *= i
    return fact

#Input list
list1 = [1, 2, 3, 4]
list1_factorials = [factorial(value) for value in list1]

#Printing output
list1_factorials
				
			

Output :

				
					[1, 2, 6, 24]
				
			

Related Articles

Remove the duplicate string from the list

Get a list of Fibonacci numbers from 1 to 20

76. Problem to remove the duplicate string from the list.

In this Python list program, we will take a user input as a list and remove the duplicate string from the list with the help of the below-given steps.

Remove the duplicate string from list:

Steps to solve the program
  1. Take a list containing strings as input.
  2. Add the strings from the given list to another list using for loop. 
  3. If a string repeats then do not add it.
  4. Print the list to see the output.
				
					#Input lists
list1 = ["python", "is", "a", "best", "language", "python", "best"]
list2 = []

for words in list1:
    if words not in list2:
        list2.append(words)

#Printing output
print(list2)
				
			

Output :

				
					['python', 'is', 'a', 'best', 'language']
				
			

Related Articles

Insert an element before each element of a list

Calculate the factorial of each item in the list

75. Problem to insert an element before each element of a list.

In this Python list program, we will take a user input as a list and insert an element before each element of a list with the help of the below-given steps.

Insert an element before each element in list:

Steps to solve the program
  1. Take a list as input.
  2. Add ‘a’ before each element of the list using list comprehension.
  3. Print the output to see the result.
				
					#Input list
list1 = [3, 5, 7, 8]
list1 = [text for value in list1 for 
         text in ('a', value)]

#Printing output
print(list1)
				
			

Output :

				
					['a', 3, 'a', 5, 'a', 7, 'a', 8]
				
			

Related Articles

Remove duplicate tuples from the list

Remove the duplicate string from the list

74. Problem to remove duplicate tuples from the list.

In this Python list program, we will take a user input as a list and remove duplicate tuples from the list with the help of the below-given steps.

Remove duplicate tuples from list:

Steps to solve the program
  1. Take a list of tuples as input.
  2. Using for loop add the tuples from the given list to another list.
  3. If a tuple repeats then do not add it.
  4. Print the output to see the result.
				
					#Input list
list1 = [(2, 3), (4, 6), (5, 1), (2, 3), (7, 9), (5, 1)]
list2 = []

for value in list2:
    if value not in list2:
        list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					[(2, 3), (4, 6), (5, 1), (7, 9)]
				
			

Related Articles

Create a list by taking an alternate item.

Insert an element before each element of a list

73. Problem to create a list by taking an alternate item.

In this Python list program, we will take a user input as a list and create a new list by taking an alternate item from the list with the help of the below-given steps.

Create a list with alternate items:

Steps to solve the program
  1. Take a list as input.
  2. Create a new list that will contain alternate elements from the given list.
  3. Use for loop with range function for this purpose.
  4. Print the new list to see the output.
				
					#Input lists
list1 = [3, 5, 7, 8, 2, 9, 3, 5, 11]
list2 = []

for i in range(0,len(list1),2):
    list2.append(list1[i])

#Prinitng output
print(list2)
				
			

Output :

				
					[3, 7, 2, 3, 11]
				
			

Related Articles

Remove duplicate sublists from the list

Remove duplicate tuples from the list

72. Problem to remove duplicate sublists from the list.

In this Python list program, we will take a user input as a list and remove duplicate sublists from the list with the help of the below-given steps.

Remove duplicate sublists:

Steps to solve the program
  1. Take a list of sublists as input.
  2. Add the sublists from the given list to another list.
  3. Use for loop for this purpose.
  4. If a sublist repeats do not add it to the other list use an iif statement for this purpose.
  5. Print the list to see the output.
				
					#Input list
list1 = [[1, 2], [3, 5], [1, 2], [6, 7]]
list2 = []

for value in list1:
    if value not in list2:
        list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					[[1, 2], [3, 5], [6, 7]]
				
			

Related Articles

Elements are unique or not from the given list

Create a list by taking an alternate item

71. Problem to check elements are unique or not in the given list.

In this Python list program, we will take a user input as a list and check if the elements are unique or not in the given list with the help of the below-given steps.

List elements are unique:

Steps to solve the program
  1. Take a list as input.
  2. Check whether all elements are unique or not from the given list using for loop and if statement.
  3. If even one element repeats in the list break the loop.
  4. If they are unique print True otherwise False.
				
					#Input list
list1 = [2, 5, 6, 7, 4, 11, 2, 4, 66, 21, 22, 3]

for i in range(len(list1)):
    if list1[i] not in list1[i+1:]:
        print("True")
        break
    else:
        print("False")
        break
        
list1 = [2, 5, 8, 3, 6, 21]

for i in range(len(list1)):
    if list1[i] not in list1[i+1:]:
        print("True")
        break
    else:
        print("False")
        break
				
			

Output :

				
					False

True
				
			

Related Articles

Remove duplicate dictionaries from a given list

Remove duplicate sublists from the list