DEV Community

loading...

Discussion on: Daily Challenge #278 - Find all non-consecutive numbers

Collapse
rafaacioly profile image
Rafael Acioly • Edited

Python solution 🐍

from typing import List, Dict


def non_consecutive(numbers: List[int]) -> List[Dict]:
  result: List[Dict] = []
  last_number =  numbers[0]
  for index, current_number in enumerate(numbers[1:], start=1):
    if not current_number - 1 == last_number:
      result.append({'i': index, 'n': number})

    last_number = number

  return result