How to Develop a Python Program that Reads Names from Console & Matches them to Dataset

python, programming, dictionary, words, match

Python program to read the names of boys and girls from a text file in a list then ask user for girl and boy names then check the number of duplicate names exists in dataset and then telling the users its count

Solution:

import os
 
BoyNames=[“”]
GirlNames=[“”]
def Main():
    
   Boy = raw_input(‘Enter Boy Name: ‘)
   Girl =  raw_input(‘Enter Girl Name: ‘)

    
   
   BoyNames = open(“BoyNames.txt”).readlines()
   GirlNames = open(“GirlNames.txt”).readlines()
   list1 = [element.upper() for element in BoyNames]
   list2 = [element.upper() for element in GirlNames]
 
   matchingboy = [s for s in list1 if Boy.upper() in s]
   print (“Matching Boy Names :- “)
   print (str(len(matchingboy)))
   print (matchingboy)
   print (“Matching Girl Names :- “)
 
   matchinggirl = [s for s in list2 if Girl.upper() in s]
   print (matchinggirl)
   print (str(len(matchinggirl)))
Main()    

 

Output Screens:

output, python. dictionary, matching

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here