In: Computer Science
python program
You are going to write a program that takes two inputs: A string representing a list of names of the following form: first name 1, last name 1, (nick name 1); first name 2, last name 2, (nick name 2); ... A string representing part of or the complete family name. You are going to output all nick names for those names where there is a partial or complete match of the family name. If no match was found you should output: Not found! Here a few examples.
Names: Chun Kit, Chui (Kit gor); Dirk, Schnieders (Dirk); Jun-fan, Lee (Bruce); Rowan Sebastian, Atkinson (Bean)
Family name: Schni
Dirk
import re
#function matching family names
def checkName(supernames,familyname) :
c=0
for i in range(4):
if
(supernames[i][1].find(familyname) == -1): #checking family name
matched or not
pass
else:
c=c+1
print(supernames[i][2]) #printing matched nick
name
if(c==0):
print("No match") #if
no family names matched
#main program
supernames=[]
for i in range(4):
name=input("Enter first name ,last name ,(nick name)
:")
date=re.split(', | \(|\)|; ',name)
#regular expression for taking provided fomat input
date.pop()
supernames.append(date) #for list in
lists
familyname=input("Family name : ") #taking family name
for family
checkName(supernames,familyname)