fork download
  1. def count_adjacent_occurrences(lst):
  2. if not lst or len(lst) < 2:
  3. return 0
  4.  
  5. count = 0
  6.  
  7. for i in range(len(lst) - 1):
  8. if lst[i] == lst[i + 1]:
  9. count += 1
  10.  
  11. return count
  12.  
  13. # Example usage:
  14. input_list = [1, 1, 5, 100, -20, -20, 6, 0, 0]
  15. output_count = count_adjacent_occurrences(input_list)
  16. print(output_count) # Output: 3
  17.  
Success #stdin #stdout 0.01s 7180KB
stdin
Standard input is empty
stdout
3