Search code examples
pythonpython-3.xfunctools

How to write python program to Combine second letters of the two strings using reduce()


Combine second letters of the two strings in the following using reduce().

string1 = [‘Hello’,’Bye’]

output should be ‘ey’


Solution

  • Here is the code for that:

    from functools import *
    
    string1 = ['Hello','Bye']
    print (reduce(lambda a,b : a+b,(i[1] for i in string1)))
    

    Output:

    ey