how do we switch two letters in a word which is in a double tuple using list comprehension?

I don’t think the initial logic is correct for your list comprehension. You want to look for tuple pairs that contain two strings of length of at least 1 and swap the last and first characters of the first and second strings respectively:

switch_L = [L[:-1] + R[0] + L[-1] + R[1:] for L,R in split_l if len(L) > 0 and len(R) > 0]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top