Print all the numbers which are less than given key element from a given list.
Python Program to get an element and print the elements of list which is lesss than the element.
Sample Input 1:
5 5 7 9 3 1 4
Sample Output 1:
Sample Input 2:
5 5 7 9 3 1 8
Sample Output 2:
5 7 3 1
Try your Solution
Strongly recommended to Solve it on your own, Don't directly go to the solution given below.
Program or Solution
l=list(map(int,input("Enter array elements:").split(" "))) e=int(input("Enter a number:")) for i in range(0,len(l)): if(l[i]<e): print(l[i],end=" ")
Input: To get list of numbers seprated by space, use split(" ") method.
Split() method splits the numbers as seprate elements.
By default this methods are considered as string, since input() method returs string. Use map() function to convert all elements as integer and store it in list.
Process: using for loop visit each location sequentially from 1 to len(l)-1. if the value located in a postion is lesser than the element given by user, then print the value using print statement.
- list input in python
- sum of list in python | without using built-in function
- Average of list in python | without using built-in function
- linear search in python
- largest element in the list python | without using built-in function
- smallest element in the list python | without using built-in function
- delete element in list python
- Revese the elements in list python
- Reverse the first half of list elements in python
- Reverse the second half of list elements in python
- list sort python
- list sort descending order python
- Python Program to sort half of the list elements in ascending order and next half in descending order.
- merging two lists in python
- Python Program to replace every element with the greatest element on right side
- circular list rotation in python