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.


Input -

firstNames = ['Albert', 'Isaac']

lastNames = ['Einstein', 'Newton']

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

2 answers to this question.

0 votes


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]+'.')    

Hope this will give you some idea.

answered Apr 21, 2020 by MD
• 95,320 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 =[]


temp =" "
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,970 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,880 points
+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,780 points
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
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
+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
0 votes
1 answer
0 votes
1 answer