Python – Custom Lower bound a List

PythonServer Side ProgrammingProgramming

When it is required to customize the lower bound on a list, a list comprehension can be used and a specific condition can be placed in it.

Below is a demonstration of the same −


 Live Demo

my_list = [51, 71, 86, 21, 11, 35, 67]

print("The list is :")

K = 50
print("The value of K is ")

my_result = [element if element >= K else K for element in my_list]

print("The result is :")


The list is :
[51, 71, 86, 21, 11, 35, 67]
The value of K is
The result is :
[51, 71, 86, 50, 50, 50, 67]


  • A list of integers is defined and is displayed on the console.

  • A value for K is defined and is displayed on the console.

  • A list comprehension is used to iterate over the elements and check if an element in the list is greater than or equal to K.

  • If yes, the element is stored in a list, otherwise the value of K is stored in the list.

  • This is assigned to a variable.

  • This is displayed as output on the console.

Updated on 06-Sep-2021 07:54:32