From 09c7f313f36442482ebde8aaad20c96d0d53edbe Mon Sep 17 00:00:00 2001 From: Tej Pratap Yadav Date: Sat, 3 Oct 2020 08:53:13 +0530 Subject: [PATCH] Added an example of map function --- map_example.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 map_example.py diff --git a/map_example.py b/map_example.py new file mode 100644 index 0000000..e3029f3 --- /dev/null +++ b/map_example.py @@ -0,0 +1,11 @@ +#This is to demonstrate the use of map function in python +#Problem Statement: Using the function Map, count the number of words that start with ā€˜Sā€™ in input_list. +#Sample Input: ['Santa Cruz','Santa fe','Mumbai','Delhi'] +#Sample Output: 2 + +#Solution: +input_list = ['Santa Cruz','Santa fe','Mumbai','Delhi'] + +count = sum(map(lambda x: x[0] == 'S', input_list)) + +print(count) # Output: 2