easy +8 pts

Find all numbers in text

Extract every standalone integer from a string as a list, ignoring decimals and numbers embedded in words.

Write a function `find_numbers(text: str) -> list` that takes a string `text` and returns a list of all integers that appear as standalone numeric tokens. A valid token is an optional sign (`+` or `-`) followed by one or more digits. The token must be surrounded by non-alphanumeric characters (or string boundaries). This means: - Numbers attached to letters (like `abc123` or `123abc`) are NOT counted. - Decimal numbers like `3.14` are NOT counted as a single number, but because the decimal point is non-alphanumeric, the integer parts `3` and `14` ARE counted as separate tokens. - Empty strings return an empty list. - Return the integers in the order they appear in the text. Your solution should use the `re` module.

Constraints

- Input length: 0 to 10,000 characters. - Numbers can be negative, positive, or zero. - Output is a list of integers in appearance order.

Example

```python
>>> find_numbers("I have 5 apples and -3 oranges")
[5, -3]
>>> find_numbers("The price is 3.14 dollars")
[3, 14]
>>> find_numbers("No numbers here!")
[]
>>> find_numbers("abc123def")
[]
```
8 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use a regular expression that matches a sign and digits, and ensure the match is not adjacent to alphanumeric characters.
Use word boundaries or lookarounds to match standalone tokens.
Remember to convert the matched strings to integers with `int()`.
Test with numbers attached to letters, decimals, and signed numbers.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.