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 1,948 views

## 2 answers to this question.

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
• 95,440 points

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
• 65,910 points

## 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

## 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

## 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

## how can i use the sum function in a python list?

If there is list =[1,2,4,6,5] then use ...READ MORE

## Docker swarm vs kubernetes

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

## Web UI (Dashboard): https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/

Hey @nmentityvibes, you seem to be using ...READ MORE

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

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

## How do I go from development docker-compose.yml to deployed docker-compose.yml in AWS

It can work if you try to put ...READ MORE