Input a list/tuple of elements and search for a given element in the list/tuple Python Program Show
# Python Program to input a list of 5 elements and search element in List mylist = [] print("Enter 5 elements for the list: ") for i in range(5): value = int(input()) mylist.append(value) print("Enter an element to be search: ") element = int(input()) for i in range(5): if element == mylist[i]: print("\nElement found at Index:", i) print("Element found at Position:", i+1)Output: You may also Check :
Python | Find the tuples containing the given element from a list of tuplesGiven a list of tuples, the task is to find all those tuples containing the given element, say n.
There are multiple ways we can find the tuples containing the given element from a list of tuples. Let’s see some of Pythonic ways to do this task. Python3
Output:
[(14, 3), (1, 3), (3, 3)]
Python3
Output:
[(11, 22), (11, 44), (33, 22, 100, 11), (99, 11)]
Article Tags :
Python
Python tuple-programs python-tuple Code:# Python code to find the tuples containing # the given element from a list of tuples # List of tuples Input = [(14, 3),(23, 41),(33, 62),(1, 3),(3, 3)] # Find an element in list of tuples. Output = [item for item in Input if item[0] == 3 or item[1] == 3] # printing output print(Output)Explanation:
Output:Thank you for learning from this post. We wish all of the best for class 11 computer science with python exams. Python is one of the most easiest and powerful language. I am impressed that CBSE is teaching Python. I feel if you go into information and communication field your carrier will be secured. Python is mainly used in data analysis and artificial intelligence programs and software’s. With the whole new generation of students in CBSE board learning Python it gives me pride to devote time for solving and presenting the work. This practical file questions are solved by Experts and every day Programmers. Here we have presented the code in most simple way of programming and yet the most powerful code for our practical. For securing full marks bookmark this website as it will help you to sail through Practicals, projects and pythons questions and answers of CBSE computer science (Python.. I am sure computer science work is nice and benefit the learners. Here below whole practical Practical file is given with link. Computer Science with Python Practical Book Solutions Class 11 Term -2 – CS Study RelatedFind the tuples containing the given element from a list of tuples in PythonPythonServer Side ProgrammingProgramming A list can have tuples as its elements. In this article we will learn how to identify those tuples which contain a specific search element which is a string. |