Advertisement
Guy_Lalonde

CS101 lesson 6 Long_repetition

Jul 29th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. def repeat_number(n, lst):
  2. repeat = 1
  3. while n < (len(lst) - 1):
  4.  
  5. if lst[n] != lst[n+1]:
  6. return repeat
  7. else:
  8. repeat = repeat +1
  9. n = n+1
  10. # print repeat
  11. return repeat
  12.  
  13.  
  14.  
  15. def longest_repetition(lst):
  16. dictA = {}
  17. n = 0
  18. if len(lst) == 0:
  19. return None
  20. while n < len(lst):
  21. if lst[n] not in dictA:
  22. dictA[lst[n]] = 0
  23. if repeat_number(n, lst) > dictA[lst[n]]:
  24. dictA[lst[n]] = repeat_number(n, lst)
  25. n = n+1
  26. # print dictA
  27. return max(dictA, key=dictA.get)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement