I want to do this to 2 different lists consisting of strings with:
list_A = ['Krish', 'Ram', 'Rajaa']
list_B = ['Sweet', 'Joy', 'Discipline']
I've written:
def Srinivasaragavansir(x,y):
out= x[0].upper() x[1:] " " y[0].upper() y[1:]
return(out)
When I run Srinivasaragavansir(list_A,list_B)
I get:
TypeError: can only concatenate str (not "list") to str
CodePudding user response:
`
so here the answer the things you are doing is you are adding string to to the list. ex x[0].upper() this return string and x[1:] and this return list so here you are adding list two string which is wrong.
if you wana add then you can add list together x[1:] y[1:] ['Ram','Rajaa''Joy','Discipline] and to add string together x[0].upper() " " y[0].upper() "KRISH SWEET" you can solve it in this way
`
CodePudding user response:
This should work you i guess
import functools
def Srinivasaragavansir(x, y):
out1 = functools.reduce(lambda i,j: str(i) ' ' str(j),x[1:],x[0].upper())
out2 = functools.reduce(lambda i, j: str(i) ' ' str(j), y[1:], y[0].upper())
out = out1 ' ' out2
return out
list_A = ['Krish', 'Ram', 'Rajaa']
list_B = ['Sweet', 'Joy', 'Discipline']
print(Srinivasaragavansir(list_A,list_B))