DEV Community

Discussion on: Daily Challenge #215 - Difference of 2

Collapse
 
vidit1999 profile image
Vidit Sarkar

Python solution

pairDifference = lambda lst: sorted([(num,num+2) for num in lst if (num+2) in lst])

print(pairDifference([1, 2, 3, 4])) # output [(1, 3), (2, 4)]
print(pairDifference([4, 1, 2, 3])) # output [(1, 3), (2, 4)]
print(pairDifference([1, 23, 3, 4, 7])) # output [(1, 3)]
print(pairDifference([4, 3, 1, 5, 6])) # output [(1, 3), (3, 5), (4, 6)]
print(pairDifference([1,3,4,6])) # output [(1, 3), (4, 6)]
Collapse
 
savagepixie profile image
SavagePixie

Whoa, that reads almost as if it were English!

Collapse
 
vidit1999 profile image
Vidit Sarkar

Thanks!