- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Remove tuples from list of tuples if greater than n in Python
When it is required to remove tuples from a list of tuples if it is greater than a value 'n', the lambda function can be used.
Anonymous function is a function which is defined without a name. In general, functions in Python are defined using 'def' keyword, but anonymous function is defined with the help of 'lambda' keyword.
It takes a single expression, but can take any number of arguments. It uses the expression and returns the result of it.
Below is a demonstration for the same −
my_tuple = [('a', 130), ('b', 230), ('c', 25),('z', 654), ('f', 69)] print("The list of tuple is : ") print(my_tuple) my_result = [i for i in my_tuple if i >= 100] print ("The resultant list of tuple is : ") print(my_result)
The list of tuple is : [('a', 130), ('b', 230), ('c', 25), ('z', 654), ('f', 69)] The resultant list of tuple is : [('a', 130), ('b', 230), ('z', 654)]
- A list of tuple is defined, and is displayed on the console.
- It is iterated over, and checked if any element is greater than or equal to zero.
- If yes, it is converted into a list.
- This operation's data is stored in a variable.
- This variable is the output that is displayed on the console.
- Related Articles
- Remove duplicate tuples from list of tuples in Python
- Python – Remove Tuples with difference greater than K
- Remove tuples having duplicate first value from given list of tuples in Python
- Python | Remove empty tuples from a list
- Python – Filter Tuples Product greater than K
- Remove tuple from list of tuples if not containing any character in Python
- Combining tuples in list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- Python – Remove Tuples from a List having every element as None
- Remove Tuples from the List having every element as None in Python
- Find the tuples containing the given element from a list of tuples in Python
- Remove matching tuples in Python
- Remove Tuples of Length K in Python
- Accessing nth element from Python tuples in list
- Python program to find Tuples with positive elements in List of tuples