97. Problem to remove duplicate dictionaries from the list.

In this Python list program, we will take a list containing dictionaries and remove duplicate dictionaries from the list with the help of the below-given steps.

Remove duplicate dictionaries from list:

Steps to solve the program
  1. Take a list containing dictionaries as input and create an empty dictionary.
  2. Use for loop to iterate over each dictionary from the given list.
  3. Add that list to the empty list if it is not in that list.
  4. Print the list to see the output.
				
					#Input list
list1 = [{'Hello': 5},{'student': 7},{'are': 3},{'learning': 8},
         {'Python': 6},{'Its': 3},{'Language': 8},{'are':3}]
list2 = []

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

#Printing output
print(list2)
				
			

Output :

				
					[{'Hello': 5}, {'student': 7}, {'are': 3}, 
{'learning': 8}, {'Python': 6}, {'Its': 3}, {'Language': 8}]
				
			

Related Articles

Python program to decode a run-length encoded given list.

Python program to round every number in a given list of numbers and print the total sum of the list.

Python Program to get the Median of all the elements from the list.

Python Program to get the Standard deviation of the list element.

Python program to convert all numbers to binary format from a given list.

Python program to convert all the numbers into Roman numbers from the given list.

 

 

 

Get length of each word and add it as dictionary

Decode a run-length encoded list

96. Problem to get the length of each word and add it as dictionary

In this Python list program, we will take a user input as a list and get length of each word and add it as a dictionary with the help of the below-given steps.

Get length of each word in list:

Steps to solve the program
  1. Take a list containing words as input.
  2. Create an empty dictionary and a list.
  3. Use for loop to iterate over each word in the given list and add the word as key in the dictionary and its length as value.
  4. Add that dictionary to the list.
  5. Print the list to see the output.
				
					#Input list
list1 = ["Hello", "student", "are", "learning", "Python", "Its", "Python", "Language"]
dictionary = dict()
list2 = []

for value in list1:
    dictionary[value]=len(value)
list2.append(dictionary)

#Printing list
print(list2));
				
			

Output :

				
					[{'Hello': 5, 'student': 7, 'are': 3, 'learning': 8, 
'Python': 6, 'Its': 3, 'Language': 8}]
				
			

Related Articles

Python program to remove duplicate dictionaries from the given list.

Python program to decode a run-length encoded given list.

Python program to round every number in a given list of numbers and print the total sum of the list.

Python Program to get the Median of all the elements from the list.

Python Program to get the Standard deviation of the list element.

Python program to convert all numbers to binary format from a given list.

 

 

 

Remove the 2nd character of each word from list

Remove duplicate dictionaries from the list

95. Problem to remove the 2nd character of each word from list.

In this Python list program, we will take a user input as a list and remove the 2nd character of each word from the list with the help of the below-given steps.

Remove the 2nd character from words in list:

Steps to solve the program
  1. Take a list of words as input.
  2. Use a for loop to iterate over words in the list.
  3. Remove the 2nd character of each word from the given list using indexing.
  4. After removing the character add those words to another list.
  5. Print the list to see the output.
				
					#Input list
list1 = ["Hello", "student", "are", "learning", 
         "Python", "Its", "Python", "Language"]
list2 = []

for value in list1:
    list2.append(value[:1]+value[2:])

#printing output
print(list2)
				
			

Output :

				
					['Hllo', 'sudent', 'ae', 'larning', 'Pthon', 
'Is', 'Pthon', 'Lnguage']
				
			

Related Articles

Convert 3rd character of each word to capital

Get length of each word and add it as dictionary

94. Problem to convert the character of each word to capital letter

In this Python list program, we will take a user input as a list and convert 3rd character of each word to the capital with the help of the below-given steps.

The character of each word to capital letter:

Steps to solve the program
  1. Take a list containing words as input.
  2. Use a for loop to iterate over words in the list.
  3. If the length of the word is greater than 3 then convert the 4th character of each word to capital using indexing and the upper() function.
  4. If not then add that word to the empty list.
  5. Add the new words to another list.
  6. Print the list to see the result.
				
					#Input list
list1 = ["Hello", "student", "are", "learning", 
         "Python", "Its", "Python", "Language"]
list2 = []
for value in list1:
    if len(value)>3:
        list2.append(value[:3]+value[3].upper()
                     +value[4:])
    else:
        list2.append(value)
        
#Printing output
print(list2)
				
			

Output :

				
					['HelLo', 'stuDent', 'are', 'leaRning', 'PytHon', 'Its', 'PytHon', 'LanGuage']
				
			

Related Articles

Replace ‘Java’ with ‘Python’ from the given list

Remove the 2nd character of each word from list

93. Problem to replace Java with Python from the given list.

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

Replace Java with Python in a list:

Steps to solve the program
  1. Take a list containing words as input.
  2. Use a for loop with the range function to iterate over words in the list.
  3. If a word is equal to Java replace it with Python.
  4. Print the list after replacing it with the above words to see the output.
				
					#Input list
list1 = ["Hello", "student", "are", "learning", "Python", "Its", "Python", "Language"]
for i in range(len(list1)):
    if list1[i] == "Python":
        list1[i] = "Java"

#Printing output
print(list1)
				
			

Output :

				
					['Hello', 'student', 'are', 'learning', 'Python',
'Its', 'Python', 'Language']
				
			

Related Articles

Create a dictionary from a sublist in given list

Convert 3rd character of each word to capital

92. Problem to create a dictionary from a sublist in given list

In this Python list program, we will take a list of sublists as input and create a dictionary from a sublist in given list with the help of the below-given steps.

Create dictionary from a sublist:

Steps to solve the program
  1. Take a list of sublists as input.
  2. Convert the given list into a dictionary using dict() and assign it to a variable.
  3. Print the variable to see the result.
				
					#Input list
list1 = [["a", 5], ["b", 8], ["c", 11], ["d", 14], ["e", 23]]

#Converting to dictionary
dictionary = dict(list1)

#Printing output
print(dictionary)
				
			

Output :

				
					{'a': 5, 'b': 8, 'c': 11, 'd': 14, 'e': 23}
				
			

Related Articles

Convert tuples in list into a sublist

Replace ‘Java’ with ‘Python’ from the given list

91. Problem to convert tuples in list into a sublist.

In this Python list program, we will take a list of tuples as input and convert tuples in list into a sublist with the help of the below-given steps.

Convert tuples in list to sublist:

Steps to solve the program
  1. Take a list containing tuples as input.
  2. Using for loop convert tuples in list to sublist.
  3. If the iterated element has type tuple then use nested for lopp to iterate over elements in the tuple.
  4. Add the elements to the empty list using the append() function
  5. And add those lists as sublists to another list.
  6. Print the list to see the result.
				
					#input list
list1 = [(3, 5), (6, 8), (8, 11), (12, 14), (17, 23)]
list2 = []

for value in list1:
    if type(value) is tuple:
        list3 = []
        for var in value:
            list3.append(var)
        list2.append(list3)

#Printing output
print(list2)
				
			

Output :

				
					[[3, 5], [6, 8], [8, 11], [12, 14], [17, 23]]
				
			

Related Articles

Flatten given nested list structure

Create a dictionary from a sublist in given list

90. Problem to flatten given nested list structure.

In this Python list program, we will take a user input as a nested list and flatten given nested list structure with the help of the below-given steps.

Flatten given nested list:

Steps to solve the program
  1. Take a nested list as input.
  2. Flatten given nested into a single list using for loop.
  3. If the iterated element is a list then add the elements in that list to the empty list.
  4. Use the type() function to check for list type.
  5. If not then also add the element to the empty list.
  6. Print the list to see the result.
				
					#Input lists
list1 = [0, 12, [22, 32], 42, 52, [62, 72, 82], [92, 102, 112, 122]]
list2 = []

for value in list:
    if type(value) is list:
        for var in value:
            list2.append(var)
    else:
        list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					[0, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122]
				
			

Related Articles

Get the list of palindrome strings

Convert tuples in list into a sublist

89. Problem to get the list of palindrome strings.

In this Python list program, we will take a user input as a list and get the list of palindrome strings from the given list with the hep of the below-given steps.

List of palindrome strings:

Steps to solve the program
  1. Take a list of strings as input and create an empty string to create a list of palindrome strings.
  2. Use for loop to iterate over each string from the list
  3. During iteration check, if the string is equal to its reverse order.
  4. If yes then add that string to the empty list.
  5. Print the list to see the result.
				
					#Input lists
list1 = ["data", "python", "oko", "test", "ete"]
list2 = []

for value in list1:
    new = value[::-1]
    if new == value:
        list2.append(value)

#Printing output
print(list2)
				
			

Output :

				
					['oko', 'ete']
				
			

Related Articles

Calculate marks percentage from the given list

Flatten given nested list structure

88. Problem to calculate marks percentage from the given list

In this Python list program, we will take a user input as a list and calculate marks percentage from a given mark list, the max mark for each item is 100 with the help of the below-given steps.

Calculate marks percentage:

Steps to solve the program
  1. Take a list containing marks as input.
  2. Calculate the percentage based on the marks in the list using general formula.
  3. Print the output. 
				
					#Input list
list1 = [80, 50, 70, 90, 95]

#Printing output
print("Percentage: ", (sum(list1)/500)*100)
				
			

Output :

				
					Percentage:  77.0
				
			

Related Articles

Calculate bill per fruit purchased from a list

Get the list of palindrome strings