Day 17 - Python

Problem Statement: Narendra Modi and Digital India

You are required to develop a Python program that extracts mentions of Narendra Modi and Digital India schemes from a given text input. The program should use regular expressions to identify the Digital India schemes mentioned in the input text. Digital India schemes include Jan Dhan Yojana, Aadhaar, BharatNet, DigiLocker, e-NAM, MyGov, UMANG, e-Sign, and BHIM.

Your task is to implement the extract_digital_initiatives function, which takes a text string as input and returns a list of Digital India schemes mentioned in the text.

Input:

The input consists of a single string representing the text mentioning Narendra Modi and Digital India schemes.

Output:

The program should output the list of Digital India schemes mentioned in the input text.

Sample Input:

Narendra Modi's government has been actively promoting Digital India to transform the country into a digitally empowered society. Initiatives like Jan Dhan Yojana, Aadhaar, BharatNet, and DigiLocker are key components of this vision. Additionally, e-NAM has revolutionized agricultural markets, while MyGov provides a platform for citizen engagement. UMANG offers a single platform for accessing various government services, and e-Sign enables digital signatures for documents. BHIM, the digital payment app, has gained widespread popularity among Indians.

Sample Output:

Jan Dhan Yojana

Aadhaar

BharatNet

DigiLocker

e-NAM

MyGov

UMANG

e-Sign

BHIM

Test Cases:

Test Case 1:

Input:

Narendra Modi launched the ambitious Digital India campaign to ensure the availability of government services online. Key initiatives include Jan Dhan Yojana, Aadhaar, and BharatNet.

Output:

Jan Dhan Yojana

Aadhaar

BharatNet

Test Case 2:

Input:

Digital India is a flagship program of the Indian government aimed at transforming the country into a digitally empowered society. It includes initiatives like DigiLocker, e-NAM, and MyGov.

Output:

DigiLocker

e-NAM

MyGov

Test Case 3:

Input:

The e-Sign initiative allows citizens to digitally sign documents, making processes more efficient. Narendra Modi's government has been actively promoting this and other Digital India schemes.

Output:

e-Sign

Test Case 4:

Input:

UMANG, the Unified Mobile Application for New-age Governance, provides access to various government services through a single platform. BHIM is another digital initiative promoting cashless transactions.

Output:

UMANG

BHIM

Test Case 5:

Input:

Aadhaar, the world's largest biometric identification system, has been instrumental in several Digital India initiatives. It has facilitated efficient delivery of welfare services to citizens.

Output:

Aadhaar


Test Case 5:

Input:

Narendra Modi and Digital India

Output:

<EMPTY>


SOLUTION:

import re

def extract_digital_initiatives(text):

    res = re.findall(r'(?:Jan\s+Dhan\s+Yojana|Aadhaar|BharatNet|DigiLocker|e-NAM|MyGov|UMANG|e-Sign|BHIM)', text, re.IGNORECASE)

    return res

txt = input()

result = extract_digital_initiatives(txt)

for i in result:

    print(i)


Insights:

  • The re.findall() function is used to search for all occurrences of a pattern (specified using a regular expression) within the given text.
  • The regular expression pattern  (?:Jan\s+ Dhan\s+ Yojana| Aadhaar| BharatNet| DigiLocker|e-NAM|MyGov|UMANG|e-Sign| BHIM) is designed to match mentions of various Digital India schemes, including Jan Dhan Yojana, Aadhaar, BharatNet, etc. The (?: ... ) syntax is a non-capturing group used for grouping multiple alternatives.
  • The re.IGNORECASE flag is used to perform a case-insensitive search, allowing matches to be found regardless of the case in which they appear in the input text.
  • The extract_digital_initiatives function takes a text string as input and returns a list of Digital India schemes mentioned in the text.
  • The extracted Digital India schemes are printed one by one using a loop. This ensures each scheme is printed on a separate line.
Join the digital revolution and embark on your coding journey to contribute to the transformation of India into a digitally empowered nation!
Happy Coding! :)

Comments