I am trying to convert the list of input words ['hdjk', 'salsap', 'sherpa'] to output: 'hdjk salsap sherpa' using the reduce()
Here is the code I am trying to work on:
from functools import reduce
input_list = ['hdjk', 'salsap', 'sherpa']
list(reduce(lambda x,y: x+" "+y, input_list)) # This gives irrelevant output
I have also tried this:
xinpl = [x.split() for x in input_list]
list(reduce(lambda x,y: x+" "+y, xinpl))
This code joins all the elements in the input_list and it works for me
print(" ".join(input_list))
I looked at other similar threads and been trying this a lot: Make List to String Python
I am still a learner. Gurus can your please help?
" ".join?listinlist(reduce(...))and it works.