Guest User

Untitled

a guest
Mar 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. def firstDupe(a):
  2. """
  3. Finding the first occurrence of any duplicates with the first second occurrence of a value
  4. as long as params are met.
  5. Returns -1 if outside params.
  6. """
  7. if len(a) == len(set(a)):
  8. return -1
  9.  
  10. indices = [a.index(i) for i in a]
  11. ilist = list()
  12. if 1 <= len(a) <= 10 ** 5: # param 1
  13. for i in range(0, len(a)):
  14. if indices[i] <= len(a): # param 2
  15. if indices[i] != i:
  16. ilist.append((i, a[i])) # ilist appends the second index occurrence
  17.  
  18. # of the dupe value
  19. else:
  20. return -1
  21. else:
  22. return -1
  23. #print(ilist)
  24. if len(ilist) == 0:
  25. return -1
  26. n = [(z, x) for z, x in ilist]
  27. print(n, min(n)[1])
  28. return min(n)[1]
  29.  
  30.  
  31. firstDupe([6, 8, 4, 9, 1, 4, 12, 5, 3, 5, 10, 12])
Add Comment
Please, Sign In to add comment