Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_1st_dup(array):
- found = {}
- for index, item in enumerate(array, start = 1):
- if item in found: return found[item]
- found[item] = index
- return -1
- def find_1st_dup_value(array):
- found = set()
- for item in array:
- if item in found: return item
- found.add(item)
- return -1
- tests = ([20, 10, 30, 50, 30, 20],
- [2, 4, 3, 5, 1],
- [5, 3, 4, 3, 6, 5],
- [400, 299, 170, 70, 40, 500, 60, 99, 299, 76])
- for test in tests:
- print(f'index: {test} is {find_1st_dup(test)}')
- print(f'value: {test} is {find_1st_dup_value(test)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement