Q:

Find all the numbers in an array whoes difference less than or equal to K

I want to find two numbers A[i] and A[j] whose difference is less than or equal to K, I need to store index of such numbers in array L (Left) R (Right) and return L & R 
def fun(A, k): 
    n = len(A)
    l = 0
    r = n-1
    # traverse the array for the two elements 
    while l<r: 
        if (A[l] - A[r] <= n):
            return A[l],A[r]
        elif (A[l] - A[r] < n): 
            l += 1
        else: 
            r -= 1
    return 0

# Driver code to test above function 
A = [3.5,5,6,12,13] 
k = 1.7
print(fun(A, k))

Expected output:
L[0,0,1,3,3],R[1,2,2,4,4]

A:

You should use itertools.combinations to get all possible combinations, then test their differences and append if needed. 
from itertools import combinations

def fun(A, k):
    l, r = [], []
    for (x_idx, x_val), (y_idx, y_val) in combinations(enumerate(A), 2):
        if abs(x_val - y_val) <= k:
            l.append(x_idx)
            r.append(y_idx)
    return l, r

Test:
A = [3.5,5,6,12,13] 
k = 1.7
print(fun(A, k))
# ([0, 1, 3], [1, 2, 4])

Though it's not your expected output, I feel like your expected output may have a few errors according to your logic.