Press "Enter" to skip to content

How to Filter Data Using Reduction Functions in Python

Here is a Python program to filter data using reduction functions.

Filter Data in Python Example

The following Python program will check for the CSV files in the current folder and will print the status. Also, it will print the minimum quantity from the list of dictionaries.

import os
files = os.listdir(os.path.expanduser('.'))
if any(name.endswith('.csv') for name in files):
    print('There are CSVs!')
else:
    print('Sorry, no CSV files in current folder.')

s = ('APPLE', 30, 223.45)
print(','.join(str(x) for x in s))

fruits = [
   {'name':'APPLE', 'quantity': 150},
   {'name':'MANGO', 'quantity': 175},
   {'name':'ORANGE', 'quantity': 120},
   {'name':'PAPAYA', 'quantity': 165}
]
min_qty = min(s['quantity'] for s in fruits)
print(min_qty)

Output:

There are CSVs!
APPLE,30,223.45
120

Process finished with exit code 0

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *