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!')
    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)


There are CSVs!

Process finished with exit code 0

See also:

Leave a Comment