Given some random array of numbers like (3, 5, -4, 8, 11, 1, -1, 6) and a target value 10
Find two numbers within the array that equal to the target value.
def two_Number_Sum(array, target): unique_number_set = set() for num in array: required_value = target - num if required_value in unique_number_set: return (num, required_value) else: unique_number_set.add(num) return () print(two_Number_Sum((3, 5, -4, 8, 11, 1, -1, 6), 10))
I am wondering if i can make this answer more pythonic. I don’t have a python background so a lot of times i write code like java or another language and i figure it will be good practice to critique myself and write code that is more pythonic so it becomes natural.