How can I define a function that takes a list of first names and a list of last names and returns a list of the corresponding full names where the last name is initialized

0 votes
I need to define a function called initializeNames that takes a list of first names and a list of last names, and returns a list of the corresponding full names where the last name is initialized. Assume that the input lists lengths are equal.

Example:

Input -

firstNames = ['Albert', 'Isaac']

lastNames = ['Einstein', 'Newton']

Output - ['Albert E.', 'Isaac N.']
Apr 21, 2020 in Python by subi
• 120 points
2,349 views

2 answers to this question.

0 votes

Hi@subl,

There is no pre-built function available to do your task I think. So, you have to create your own customize code according to your need. You can see this below code. It is created according to your example.

firstNames = ['Albert', 'Isaac']
lastNames = ['Einstein', 'Newton']
for i in firstNames:
    for j in lastNames:
        c.append(i+' '+j[0]+'.')    
d=[c[0],c[3]]

Hope this will give you some idea.

answered Apr 21, 2020 by MD
• 95,460 points
0 votes

Hey, @Subi,

Regarding your query, you can go through this process also, the code shown below:

str1= "albert einstein"
str2= "issac newton"

list1 =str1.split()[0].capitalize()
list2 =str1.split()[1].capitalize()

list3 =str2.split()[0].capitalize()
list4 =str2.split()[1].capitalize()

result1 =[]
result2 =[]

result1.append(list1)
result1.append(list2[0])
result2.append(list3)
result2.append(list4[0])

temp =" "
out=temp.join(result1)
put=temp.join(result2)
print(out, put)

I know its a bit lengthy process, but you will understand better. Capitalize function in python will always convert the first letter of any string into the upper-case.

 I hope this will help.

answered Apr 21, 2020 by Gitika
• 65,770 points

Related Questions In Python

0 votes
1 answer

How do I get the path and name of the file that is currently executing?

Hello @kartik, Since Python 3 is fairly mainstream, ...READ MORE

answered May 11, 2020 in Python by Niroj
• 82,840 points
2,643 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
1,418 views
0 votes
2 answers

How can I get the count of a list in Python?

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

answered Dec 10, 2020 in Python by anonymous
1,489 views
0 votes
1 answer
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
3,929 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,039 views
0 votes
1 answer

I have trained a model using machine learning algorithm in python , now i want to create a browser extension of that saved model , Is it possible ??

Hi@Shubham, It may possible. When you saved your ML ...READ MORE

answered Jun 13, 2020 in Python by MD
• 95,460 points
1,132 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP